# Controlling over I2C port

<p class="callout info">Applies to EVB.1.2.0 firmware where I2C is implemented</p>

<p class="callout info">Slave address: 0x33</p>

#### About

In order to simplify I2C communication, firmware utilizes one one direction read/write operations. All commands expect 5 bytes, where first byte is function address, remaining bytes is payload.

USB-CDC works in parallel with I2C functionality and independently, but it is recommended to use single communication channel once controller is initialized.

#### Wiring

[![MFPi2c_connection.png](https://wiki.kurokesu.com/uploads/images/gallery/2020-08/scaled-1680-/MFPi2c_connection.png)](https://wiki.kurokesu.com/uploads/images/gallery/2020-08/MFPi2c_connection.png)

<p class="callout warning">In order to avoid power loops, do not connect both (SCF4 and Arduino) USB ports at the same time.</p>

#### Write data

All commands are fixed length consisting of 5 bytes.

<table border="1" id="bkmrk-i2c-addr-function-by" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 22.0987%;">W: I2C ADDR</td><td style="width: 16.5433%;">FUNCTION</td><td style="width: 15.0618%;">BYTE1</td><td style="width: 14.6913%;">BYTE2</td><td style="width: 12.3456%;">BYTE3</td><td style="width: 19.2593%;">BYTE4</td></tr></tbody></table>

#### Read data

First issue write command (register values are ignored). This step performs necessary calculations and fills memory with registers ready for reading in next step.

<table border="1" id="bkmrk-i2c-addr-w%3Afunction-" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 22.3457%;">W: I2C ADDR</td><td style="width: 16.1728%;">FUNCTION</td><td style="width: 15.0618%;">BYTE1</td><td style="width: 14.4446%;">BYTE2</td><td style="width: 12.7159%;">BYTE3</td><td style="width: 19.2593%;">BYTE4</td></tr></tbody></table>

Read command also consists of 5 bytes. FUNCTION repeats last write command value.

<table border="1" id="bkmrk-i2c-addr-r%3Afunction-" style="border-collapse: collapse; width: 100%;"><tbody><tr><td style="width: 22.2222%;">R: I2C ADDR</td><td style="width: 16.4199%;">FUNCTION</td><td style="width: 14.8148%;">BYTE1</td><td style="width: 14.5679%;">BYTE2</td><td style="width: 12.7159%;">BYTE3</td><td style="width: 19.2593%;">BYTE4</td></tr></tbody></table>

#### Commands

<table border="1" id="bkmrk-addr-register-name-r" style="border-collapse: collapse; width: 100%; height: 464px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 10.6173%; height: 29px;">**ADDR**</td><td class="align-center" style="width: 19.7531%; height: 29px;">**REGISTER NAME**</td><td class="align-center" style="width: 5.18523%; height: 29px;">**R/W**</td><td class="align-center" style="width: 25.8027%; height: 29px;">**FUNCTION**</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x02</td><td style="width: 19.7531%; height: 29px;">**RESET\_CPU**</td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Reset STM32 CPU</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x03</td><td style="width: 19.7531%; height: 29px;">**INIT\_DRV**</td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Reset and initialize motor driver</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x05</td><td style="width: 19.7531%; height: 29px;">**AUX\_OUT**</td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Control AUX output on/off</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x06</td><td style="width: 19.7531%; height: 29px;">**MODE** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Normal / forced move</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x07</td><td style="width: 19.7531%; height: 29px;">**STOP** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Compulsory stop</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x08</td><td style="width: 19.7531%; height: 29px;">**PI\_LEDS** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Switch on ON or OFF PI LEDs</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x09</td><td style="width: 19.7531%; height: 29px;">**MOTOR\_SLEEP\_PWR** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Set motor sleep power</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x0A</td><td style="width: 19.7531%; height: 29px;">**MOTOR\_DRV\_PWR** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Set motor working power</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x0B</td><td style="width: 19.7531%; height: 29px;">**MOTOR\_SPEED** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Set motor speed</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x0C</td><td style="width: 19.7531%; height: 29px;">**PI\_THRESHOLD** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Set PI detector thresholds</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x0D</td><td style="width: 19.7531%; height: 29px;">**READ\_STATUS** </td><td style="width: 5.18523%; height: 29px;">R</td><td style="width: 25.8027%; height: 29px;">Read controller status</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x0E</td><td style="width: 19.7531%; height: 29px;">**SET\_MOTOR\_POS** </td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Set current motor position</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x0F</td><td style="width: 19.7531%; height: 29px;">**SET\_MICROSTEPPING**</td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Set motor micro-stepping mode</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x10</td><td style="width: 19.7531%; height: 29px;">**DN\_SWITCH**</td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">IR fitler</td></tr><tr style="height: 29px;"><td style="width: 10.6173%; height: 29px;">0x20</td><td style="width: 19.7531%; height: 29px;">**MOVE**</td><td style="width: 5.18523%; height: 29px;">W</td><td style="width: 25.8027%; height: 29px;">Move motor</td></tr></tbody></table>

#### Command explanation

##### `RESET_CPU` - Reset CPU

Resets CPU. Other values are ignored.

<table border="1" id="bkmrk-description-function-0" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 33.9506%; height: 29px;">**Description**</td><td class="align-center" style="width: 16.2964%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 13.3334%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 12.0987%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 33.9506%; height: 29px;">Reset CPU</td><td class="align-center" style="width: 16.2964%; height: 29px;">0x02</td><td class="align-center" style="width: 13.3334%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%; height: 29px;">**0x32**</td></tr></tbody></table>

##### `INIT_DRV` - Reset motor driver

Resets and initializes motor controller. Other values are ignored.

<table border="1" id="bkmrk-description-function" style="border-collapse: collapse; width: 100%;"><tbody><tr><td class="align-center" style="width: 33.8272%;">**Description**</td><td class="align-center" style="width: 17.6544%;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%;">**BYTE1**</td><td class="align-center" style="width: 12.0987%;">**BYTE2**</td><td class="align-center" style="width: 12.0988%;">**BYTE3**</td><td class="align-center" style="width: 12.2222%;">**BYTE4**</td></tr><tr><td style="width: 33.8272%;">Initialize motor driver</td><td class="align-center" style="width: 17.6544%;">0x03</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x32**</td></tr></tbody></table>

##### `AUX_OUT` - Control AUX output

Controls GPIO output

<table border="1" id="bkmrk-description-function-1" style="border-collapse: collapse; width: 100%;"><tbody><tr><td class="align-center" style="width: 33.7037%;">**Description**</td><td class="align-center" style="width: 17.7779%;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%;">**BYTE1**</td><td class="align-center" style="width: 12.0987%;">**BYTE2**</td><td class="align-center" style="width: 12.0988%;">**BYTE3**</td><td class="align-center" style="width: 12.2222%;">**BYTE4**</td></tr><tr><td style="width: 33.7037%;">Set AUX to Low</td><td class="align-center" style="width: 17.7779%;">0x05</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x00**</td></tr><tr><td style="width: 33.7037%;">Set AUX to High</td><td class="align-center" style="width: 17.7779%;">0x05</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x01**</td></tr></tbody></table>

##### `MODE` - Normal / forced move

Selects between normal and normal+forced move mode

<table border="1" id="bkmrk-description-function-2" style="border-collapse: collapse; width: 100%;"><tbody><tr><td class="align-center" style="width: 33.4568%;">**Description**</td><td class="align-center" style="width: 18.0248%;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%;">**BYTE1**</td><td class="align-center" style="width: 12.0987%;">**BYTE2**</td><td class="align-center" style="width: 12.0988%;">**BYTE3**</td><td class="align-center" style="width: 12.2222%;">**BYTE4**</td></tr><tr><td style="width: 33.4568%;">Normal move mode</td><td class="align-center" style="width: 18.0248%;">0x06</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;">**Channel**</td><td class="align-center" style="width: 12.2222%;">**0x00**</td></tr><tr><td style="width: 33.4568%;">Normal+Forced move mode</td><td class="align-center" style="width: 18.0248%;">0x06</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;">**Channel**</td><td class="align-center" style="width: 12.2222%;">**0x01**</td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte1-value-" style="border-collapse: collapse; width: 32.4705%;"><tbody><tr><td class="align-center" style="width: 47.2645%;">**Channel**</td><td class="align-center" style="width: 79.6539%;">**BYTE3 value**</td></tr><tr><td style="width: 47.2645%;">A</td><td class="align-center" style="width: 79.6539%;">0x01</td></tr><tr><td style="width: 47.2645%;">B</td><td class="align-center" style="width: 79.6539%;">0x02</td></tr><tr><td style="width: 47.2645%;">C</td><td class="align-center" style="width: 79.6539%;">0x03</td></tr></tbody></table>

##### `STOP` - Compulsory stop

Stop movement of all motors

<table border="1" id="bkmrk-description-function-3" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 32.8395%; height: 29px;">**Description**</td><td class="align-center" style="width: 18.6421%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 12.0987%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 32.8395%; height: 29px;">Reset CPU</td><td class="align-center" style="width: 18.6421%; height: 29px;">0x07</td><td class="align-center" style="width: 12.0988%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%; height: 29px;">**0x32**</td></tr></tbody></table>

##### `PI_LEDS` - Switch on ON or OFF PI LEDs

Control LEDs used in homing procedure.

<table border="1" id="bkmrk-description-function-4" style="border-collapse: collapse; width: 100%;"><tbody><tr><td class="align-center" style="width: 32.4692%;">**Description**</td><td class="align-center" style="width: 19.0125%;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%;">**BYTE1**</td><td class="align-center" style="width: 12.0987%;">**BYTE2**</td><td class="align-center" style="width: 12.0988%;">**BYTE3**</td><td class="align-center" style="width: 12.2222%;">**BYTE4**</td></tr><tr><td style="width: 32.4692%;">OFF</td><td class="align-center" style="width: 19.0125%;">0x08</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x00**</td></tr><tr><td style="width: 32.4692%;">ON</td><td class="align-center" style="width: 19.0125%;">0x08</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x01**</td></tr></tbody></table>

##### `MOTOR_SLEEP_PWR` - Set motor sleep power

Set motor sleep current

<table border="1" id="bkmrk-description-function-5" style="border-collapse: collapse; width: 100%;"><tbody><tr><td class="align-center" style="width: 31.9753%;">**Description**</td><td class="align-center" style="width: 19.5063%;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%;">**BYTE1**</td><td class="align-center" style="width: 12.0987%;">**BYTE2**</td><td class="align-center" style="width: 12.0988%;">**BYTE3**</td><td class="align-center" style="width: 12.2222%;">**BYTE4**</td></tr><tr><td style="width: 31.9753%;">Set current</td><td class="align-center" style="width: 19.5063%;">0x09</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;">**Channel**</td><td class="align-center" style="width: 12.2222%;">**Power**</td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte1-value--0" style="border-collapse: collapse; width: 33.7051%;"><tbody><tr><td class="align-center" style="width: 47.2645%;">**Channel**</td><td class="align-center" style="width: 84.6044%;">**BYTE3 value**</td></tr><tr><td style="width: 47.2645%;">A</td><td class="align-center" style="width: 84.6044%;">0x01</td></tr><tr><td style="width: 47.2645%;">B</td><td class="align-center" style="width: 84.6044%;">0x02</td></tr><tr><td style="width: 47.2645%;">C</td><td class="align-center" style="width: 84.6044%;">0x03</td></tr></tbody></table>

##### `MOTOR_DRV_PWR` - Set motor working power

Set motor operating current

<table border="1" id="bkmrk-description-function-6" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 34.0741%; height: 29px;">**Description**</td><td class="align-center" style="width: 17.4075%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 12.0987%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 34.0741%; height: 29px;">Set current</td><td class="align-center" style="width: 17.4075%; height: 29px;">0x0A</td><td class="align-center" style="width: 12.0988%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%; height: 29px;">**Channel**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**Power**</td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte1-value--1" style="border-collapse: collapse; width: 32.9643%;"><tbody><tr><td class="align-center" style="width: 47.2645%;">**Channel**</td><td class="align-center" style="width: 80.5746%;">**BYTE3 value**</td></tr><tr><td style="width: 47.2645%;">A</td><td class="align-center" style="width: 80.5746%;">0x01</td></tr><tr><td style="width: 47.2645%;">B</td><td class="align-center" style="width: 80.5746%;">0x02</td></tr><tr><td style="width: 47.2645%;">C</td><td class="align-center" style="width: 80.5746%;">0x03</td></tr><tr><td style="width: 47.2645%;">D</td><td class="align-center" style="width: 80.5746%;">0x04</td></tr></tbody></table>

##### `MOTOR_SPEED` - Set motor speed

Set motor speed

<table border="1" id="bkmrk-description-function-7" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 30.4939%; height: 29px;">**Description**</td><td class="align-center" style="width: 18.642%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 13.0865%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 12.716%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.8395%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 30.4939%; height: 29px;">Set speed</td><td class="align-center" style="width: 18.642%; height: 29px;">0x0B</td><td class="align-center" style="width: 13.0865%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.716%; height: 29px;">**Channel**</td><td class="align-center" style="width: 12.8395%; height: 29px;">**Speed \[15:8\]** </td><td class="align-center" style="width: 12.2222%; height: 29px;">**Speed \[7:0\]** </td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte1-value--2" style="border-collapse: collapse; width: 31.9766%; height: 145px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 47.2645%; height: 29px;">**Channel**</td><td class="align-center" style="width: 77.6737%; height: 29px;">**BYTE2 value**</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A</td><td class="align-center" style="width: 77.6737%; height: 29px;">0x01</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B</td><td class="align-center" style="width: 77.6737%; height: 29px;">0x02</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C</td><td class="align-center" style="width: 77.6737%; height: 29px;">0x03</td></tr></tbody></table>

##### `PI_THRESHOLD` - Set PI detector thresholds

Set limit switch optocoupler detector thresholds

<table border="1" id="bkmrk-description-function-8" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 29.6297%; height: 29px;">**Description**</td><td class="align-center" style="width: 18.1483%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 12.3457%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 14.0741%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 13.5802%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 29.6297%; height: 29px;">Set threshold</td><td class="align-center" style="width: 18.1483%; height: 29px;">0x0C</td><td class="align-center" style="width: 12.3457%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 14.0741%; height: 29px;">**Channel**</td><td class="align-center" style="width: 13.5802%; height: 29px;">**Signal \[15:8\]** </td><td class="align-center" style="width: 12.2222%; height: 29px;">**Signal \[7:0\]** </td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte1-value--3" style="border-collapse: collapse; width: 31.6062%; height: 203px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 47.2645%; height: 29px;">**Channel**</td><td class="align-center" style="width: 76.1886%; height: 29px;">**BYTE2 value**</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A LOW</td><td class="align-center" style="width: 76.1886%; height: 29px;">0x01</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B LOW</td><td class="align-center" style="width: 76.1886%; height: 29px;">0x02</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C LOW</td><td class="align-center" style="width: 76.1886%; height: 29px;">0x03</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A HIGH</td><td class="align-center" style="width: 76.1886%; height: 29px;">0x04</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B HIGH</td><td class="align-center" style="width: 76.1886%; height: 29px;">0x05</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C HIGH</td><td class="align-center" style="width: 76.1886%; height: 29px;">0x06</td></tr></tbody></table>

##### `READ_STATUS` - Read controller status

Read motor status, PI status and motor positions

<table border="1" id="bkmrk-description-function-9" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 32.5926%; height: 29px;">**Description**</td><td class="align-center" style="width: 18.889%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 11.358%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.8395%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 32.5926%; height: 29px;">Set current</td><td class="align-center" style="width: 18.889%; height: 29px;">0x0D</td><td class="align-center" style="width: 12.0988%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 11.358%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.8395%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%; height: 29px;">**Channel**</td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte2-value-" style="border-collapse: collapse; width: 32.9643%; height: 290px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 47.2645%; height: 29px;">**Channel**</td><td class="align-center" style="width: 81.6341%; height: 29px;">**BYTE2 value**</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A position</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x01</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B position</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x02</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C position</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x03</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">PI\_A status</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x04</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">PI\_B status</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x05</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">PI\_C status</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x06</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A moving</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x07</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B moving</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x08</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C moving</td><td class="align-center" style="width: 81.6341%; height: 29px;">0x09</td></tr></tbody></table>

Returns:

<table border="1" id="bkmrk-description-function-10" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 32.963%; height: 29px;">**Description**</td><td class="align-center" style="width: 16.173%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 13.0864%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 13.4567%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.0988%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 32.963%; height: 29px;">Status return value</td><td class="align-center" style="width: 16.173%; height: 29px;">0x0D</td><td class="align-center" style="width: 13.0864%; height: 29px;"><span style="color: #999999;"><span style="color: #333333;">**Value \[31:24\]**</span></span></td><td class="align-center" style="width: 13.4567%; height: 29px;"><span style="color: #333333;">**Value \[23:16\]**</span></td><td class="align-center" style="width: 12.0988%; height: 29px;">**Value \[15:8\]**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**Value \[7:0\]**</td></tr></tbody></table>

##### `SET_MOTOR_POS` - Set position

Redefine current position

<table border="1" id="bkmrk-description-function-11" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 29.3827%; height: 29px;">**Description**</td><td class="align-center" style="width: 16.173%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 13.3334%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 14.9382%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 13.2099%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.9629%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 29.3827%; height: 29px;">Set position</td><td class="align-center" style="width: 16.173%; height: 29px;">0x0E</td><td class="align-center" style="width: 13.3334%; height: 29px;">**Channel**</td><td class="align-center" style="width: 14.9382%; height: 29px;">**Speed \[23:16\]**</td><td class="align-center" style="width: 13.2099%; height: 29px;">**Speed \[15:8\]** </td><td class="align-center" style="width: 12.9629%; height: 29px;">**Speed \[7:0\]** </td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte2-value--0" style="border-collapse: collapse; width: 31.4828%; height: 145px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 47.2645%; height: 29px;">**Channel**</td><td class="align-center" style="width: 75.6935%; height: 29px;">**BYTE1 value**</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A</td><td class="align-center" style="width: 75.6935%; height: 29px;">0x01</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B</td><td class="align-center" style="width: 75.6935%; height: 29px;">0x02</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C</td><td class="align-center" style="width: 75.6935%; height: 29px;">0x03</td></tr></tbody></table>

##### `SET_MICROSTEPPING` - Set microstepping mode

Set microstepping mode for defined channel

<table border="1" id="bkmrk-description-function-12" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 32.2222%; height: 29px;">**Description**</td><td class="align-center" style="width: 17.531%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 11.8519%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 13.3333%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 12.8395%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.2222%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 32.2222%; height: 29px;">Set microstepping</td><td class="align-center" style="width: 17.531%; height: 29px;">0x0F</td><td class="align-center" style="width: 11.8519%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 13.3333%; height: 29px;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.8395%; height: 29px;">**Channel** </td><td class="align-center" style="width: 12.2222%; height: 29px;">**Mode** </td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte1-value--4" style="border-collapse: collapse; width: 31.4828%; height: 145px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 47.2645%; height: 29px;">**Channel**</td><td class="align-center" style="width: 75.6935%; height: 29px;">**BYTE1 value**</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A</td><td class="align-center" style="width: 75.6935%; height: 29px;">0x01</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B</td><td class="align-center" style="width: 75.6935%; height: 29px;">0x02</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C</td><td class="align-center" style="width: 75.6935%; height: 29px;">0x03</td></tr></tbody></table>

##### `MOVE` - Move motor

Move motor defined step count.

<table border="1" id="bkmrk-description-function-13" style="border-collapse: collapse; width: 100%; height: 58px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 31.2345%; height: 29px;">**Description**</td><td class="align-center" style="width: 16.9137%; height: 29px;">**FUNCTION**</td><td class="align-center" style="width: 12.5927%; height: 29px;">**BYTE1**</td><td class="align-center" style="width: 13.7037%; height: 29px;">**BYTE2**</td><td class="align-center" style="width: 13.0864%; height: 29px;">**BYTE3**</td><td class="align-center" style="width: 12.4691%; height: 29px;">**BYTE4**</td></tr><tr style="height: 29px;"><td style="width: 31.2345%; height: 29px;">Steps</td><td class="align-center" style="width: 16.9137%; height: 29px;">0x20</td><td class="align-center" style="width: 12.5927%; height: 29px;">**Channel**</td><td class="align-center" style="width: 13.7037%; height: 29px;">**Direction**</td><td class="align-center" style="width: 13.0864%; height: 29px;">**Steps \[15:8\]** </td><td class="align-center" style="width: 12.4691%; height: 29px;">**Steps \[7:0\]** </td></tr></tbody></table>

Channel encoding:

<table border="1" id="bkmrk-channel-byte2-value--1" style="border-collapse: collapse; width: 31.1124%; height: 145px;"><tbody><tr style="height: 29px;"><td class="align-center" style="width: 47.2645%; height: 29px;">**Channel**</td><td class="align-center" style="width: 74.2084%; height: 29px;">**BYTE2 value**</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">A</td><td style="width: 74.2084%; height: 29px;">0x01</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">B</td><td style="width: 74.2084%; height: 29px;">0x02</td></tr><tr style="height: 29px;"><td style="width: 47.2645%; height: 29px;">C</td><td style="width: 74.2084%; height: 29px;">0x03</td></tr></tbody></table>

<p class="callout info">MAX steps is: 0xFFFF-1 = **0xFFFE**</p>

<p class="callout info">Theia lens exceeds 0xFFFF step count, thus absolute positioning has to be implemented on client side code</p>

##### `DN_SWITCH` - IR filter swith

Switch filter to day or night position

<table border="1" id="bkmrk-description-function-14" style="border-collapse: collapse; width: 100%;"><tbody><tr><td class="align-center" style="width: 32.2222%;">**Description**</td><td class="align-center" style="width: 19.2594%;">**FUNCTION**</td><td class="align-center" style="width: 12.0988%;">**BYTE1**</td><td class="align-center" style="width: 12.0987%;">**BYTE2**</td><td class="align-center" style="width: 12.0988%;">**BYTE3**</td><td class="align-center" style="width: 12.2222%;">**BYTE4**</td></tr><tr><td style="width: 32.2222%;">POS1</td><td class="align-center" style="width: 19.2594%;">0x10</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x00**</td></tr><tr><td style="width: 32.2222%;">POS2</td><td class="align-center" style="width: 19.2594%;">0x10</td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0987%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.0988%;"><span style="color: #999999;">ignored</span></td><td class="align-center" style="width: 12.2222%;">**0x01**</td></tr></tbody></table>

#### Arduino sketch example

Demo output should look like

```shell
SCF4-M I2C tester

Init driver
Set microstepping
Move mode
PI LEDS
Set drive pwr
Set sleep pwr
Set motor speeds
Set PI thresholds
Read status: posA
D 0 0 0 0
Read status: PI A
D 0 0 0 1
Homing A
Homing B
Move +A
Move -A
Move +B
Move -B
Move +C
Move -C
Set position
DN 0
DN 1
DN 0
DN 1
Last return from I2C port: ok
Loop...
```

`tester.ino`

```C
#include <Wire.h>

#define CH_A 0x01
#define CH_B 0x02
#define CH_C 0x03
#define CH_D 0x04

#define CCW  0
#define CW   1


void err_print(byte err)
{
    if (err == 0)
    {
      Serial.println("ok");
    }
    else if (err==4)
    {
      Serial.println("failed");
    }    
}

void setup()
{
  Wire.begin();
  Serial.begin(115200);
  while (!Serial);
  Serial.println("\nSCF4-M I2C tester\n");
}    
     
void loop()
{
    byte error;
    
    Serial.println("Init driver");
    SCF4_INIT_DRIVER();

    Serial.println("Set microstepping");
    SCF4_MICROSTEPPING(2, CH_A);
    SCF4_MICROSTEPPING(2, CH_B);   
    SCF4_MICROSTEPPING(6, CH_C);

    Serial.println("Move mode");
    SCF4_MODE(0x00, CH_A);
    SCF4_MODE(0x00, CH_B);
    SCF4_MODE(0x00, CH_C);
      
    Serial.println("PI LEDS");
    SCF4_PI_LEDS(0x01);

    Serial.println("Set drive pwr");
    SCF4_DRV_PWR(180, CH_A);
    SCF4_DRV_PWR(180, CH_B);
    SCF4_DRV_PWR(180, CH_C);
    SCF4_DRV_PWR(90, CH_D);

    Serial.println("Set sleep pwr");
    SCF4_SLEEP_PWR(50, CH_A);
    SCF4_SLEEP_PWR(50, CH_B);
    SCF4_SLEEP_PWR(50, CH_C);
    
    Serial.println("Set motor speeds");
    SCF4_MOTOR_SPEED(5000, CH_A);
    SCF4_MOTOR_SPEED(5000, CH_B);
    SCF4_MOTOR_SPEED(5000, CH_C);


    Serial.println("Set PI thresholds");
    SCF4_PI_THRESHOLD(2000, 0x01);
    SCF4_PI_THRESHOLD(2000, 0x02);
    SCF4_PI_THRESHOLD(2000, 0x03);
    SCF4_PI_THRESHOLD(3000, 0x04);
    SCF4_PI_THRESHOLD(3000, 0x05);
    SCF4_PI_THRESHOLD(3000, 0x06);


    Serial.println("Read status: posA");
    SCF4_READ_STATUS(0x01);
    Serial.println("Read status: PI A");
    SCF4_READ_STATUS(0x04);


    Serial.println("Homing A");
    MOVE(30000, CW, CH_A);
    delay(2000);
    SCF4_MODE(0x01, CH_A);
    MOVE(0x100, CCW, CH_A);
    delay(15000); // status reading is not implemented, for testing 15s timeout is used
    SCF4_MODE(0x00, CH_A);
    SET_MOTOR_POS(100, CH_A);

    Serial.println("Homing B");
    MOVE(30000, CW, CH_B);
    delay(2000);
    SCF4_MODE(0x01, CH_B);
    MOVE(0x100, CCW, CH_B);
    delay(15000); // status reading is not implemented, for testing 15s timeout is used
    SCF4_MODE(0x00, CH_B);
    SET_MOTOR_POS(100, CH_B);



    // normal operation starts here
    

    
    Serial.println("Move +A");
    MOVE(0xFFFE, CW, CH_A);
    delay(5000);
    Serial.println("Move -A");
    MOVE(0xFFFE, CCW, CH_A);
    delay(5000);

    Serial.println("Move +B");
    MOVE(0xFFFE, CW, CH_B);
    delay(5000);
    Serial.println("Move -B");
    MOVE(0xFFFE, CCW, CH_B);
    delay(5000);

    Serial.println("Move +C");
    MOVE(1000, CW, CH_C);
    delay(2000);
    Serial.println("Move -C");
    MOVE(1000, CCW, CH_C);
    delay(2000);

    Serial.println("Set position");
    //SET_MOTOR_POS(100, 0x01);
    //SET_MOTOR_POS(200, 0x01);
    //SET_MOTOR_POS(300, 0x01);

    //STOP();

    Serial.println("DN 0");
    DN_SWITCH(0);
    delay(1000);
    Serial.println("DN 1");
    DN_SWITCH(1);
    delay(1000);
    Serial.println("DN 0");
    DN_SWITCH(0);
    delay(1000);
    Serial.println("DN 1");
    DN_SWITCH(1);
    delay(1000);

    
    Serial.print("Last return from I2C port: ");
    err_print(error);
               
    Serial.println("Loop...");
    while(1)
    {
    } 
}
```

`scf4_i2c.ino`

```C
// SCL - A5
// SDA - A4

#include <Wire.h>
#define SCF4_ADDR 0x33

// SCF4 is not signaling busy status, thus fixed delay is added
// If next I2C command is sent too soon it might be ignored
#define I2C_SLEEP 200


byte SCF4_AUX(byte status)
{
  byte function = 0x05;
  byte error;
  
  //byte w1 = (counter&0xFF);
  //byte w2 = ((counter>>8)&0xFF);
  //byte w3 = ((counter>>16)&0xFF);
  //byte w4 = ((counter>>24)&0xFF);
        
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(status);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_RESET_CPU(void)
{
  byte function = 0x02;
  byte error;
          
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0x32);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_INIT_DRIVER(void)
{
  byte function = 0x03;
  byte error;
          
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0x32);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_MODE(byte mode, byte ch)
{
  byte function = 0x06;
  byte error;
  
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(ch);
  Wire.write(mode);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_PI_LEDS(byte mode)
{
  byte function = 0x08;
  byte error;
  
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(mode);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_SLEEP_PWR(byte pwr, byte ch)
{
  byte function = 0x09;
  byte error;
  
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(ch);
  Wire.write(pwr);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_DRV_PWR(byte pwr, byte ch)
{
  byte function = 0x0A;
  byte error;
  
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(ch);
  Wire.write(pwr);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_MOTOR_SPEED(int speed, byte ch)
{
  byte function = 0x0B;
  byte error;
    
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(ch);
  Wire.write(highByte(speed));
  Wire.write(lowByte(speed));
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_PI_THRESHOLD(int level, byte ch)
{
  byte function = 0x0C;
  byte error;
    
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(ch);
  Wire.write(highByte(level));
  Wire.write(lowByte(level));
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_READ_STATUS(byte ch)
{
  byte function = 0x0D;
  byte error;

  /*
  * channel:
  * 0x00 - dummy, reads 0x87, 0x65, 0x43, 0x21
  * 0x01 - chA.position
  * 0x02 - chB.position
  * 0x03 - chC.position
  * 0x04 - piA.status
  * 0x05 - piB.status
  * 0x06 - piC.status
  * 0x07 - chA.moving
  * 0x08 - chB.moving
  * 0x09 - chC.moving
  */
    
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(ch);
  error = Wire.endTransmission();  

  delay(I2C_SLEEP);
  
  byte w1 = 0xff;
  byte w2 = 0xff;
  byte w3 = 0xff;
  byte w4 = 0xff;
  byte w5 = 0xff;

  Wire.requestFrom(SCF4_ADDR, 5);
  w1 = Wire.read();
  w2 = Wire.read();
  w3 = Wire.read();
  w4 = Wire.read();
  w5 = Wire.read();

  Serial.print(w1, HEX);
  Serial.print(" ");
  Serial.print(w2, HEX);
  Serial.print(" ");
  Serial.print(w3, HEX);
  Serial.print(" ");
  Serial.print(w4, HEX);
  Serial.print(" ");
  Serial.print(w5, HEX);
  Serial.println();
  
  delay(I2C_SLEEP);
    
  // TODO: return read values
  return error;
}


byte SET_MOTOR_POS(int pos, byte ch)
{
  byte function = 0x0E;
  byte error;
    
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(ch);
  Wire.write(0);
  Wire.write(highByte(pos));
  Wire.write(lowByte(pos));
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte MOVE(unsigned int steps, byte dir, byte ch)
{
  byte function = 0x20;
  byte error;
    
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(ch);
  Wire.write(dir);
  Wire.write(highByte(steps));
  Wire.write(lowByte(steps));
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte DN_SWITCH(byte mode)
{
  byte function = 0x10;
  byte error;
  
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(mode);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte SCF4_MICROSTEPPING(byte stepping, byte ch)
{
  byte function = 0x0F;
  byte error;
  
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(ch);
  Wire.write(stepping);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}

byte STOP(void)
{
  byte function = 0x07;
  byte error;
          
  Wire.beginTransmission(SCF4_ADDR);
  Wire.write(function);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0);
  Wire.write(0x32);
  error = Wire.endTransmission();
  delay(I2C_SLEEP);

  return error;
}
```