Motor protocol
--- UNDER CONSTRUCTION!!! --- More info will be added.
Introduction
The protocol for the motor board will be explained on this page.
The addresses on the bus are 7 bits wide. The lower bit specifies if the transaction is to be a read or a write. Write transactions have the lower bit cleared (0), read transactions have the lower bit set (1).
Each transaction on the bus starts with the address of the board. The motor board will ignore any transactions on the bus that do not start with its own address.
After the address a single byte indicates the "port" on the board that the data is written to. The software can thus define 256 ports on each board.
Write ports
Some ports just set a single value. So writing more than one byte to such a port is redundant. Other ports are logically a stream of bytes. So writing more than one byte is encouraged.
The motor boards defines several ports.
port | function |
---|---|
0xf0 | change address. Requires a write to 0xf1 and 0xf2 first. |
0xf1 | write 0x55 here to start unlocking the change address register. |
0xf2 | write 0xaa here to unlock the change address register. |
two separate brushed motors section.... | |
0x20 | Spin motor A in direction X with intensity <byte> |
0x21 | Spin motor A in direction Y with intensity <byte> |
0x22 | Stop motor A |
0x30 | Spin motor B in direction X with intensity <byte> |
0x31 | Spin motor B in direction Y with intensity <byte> |
0x32 | Stop motor B |
Stepper motor section.... | |
0x10 | Set drive intensity for stepper mode (default is 0x20) |
0x40 | set current position. <4 bytes> |
0x41 | set target position. <4 bytes> |
0x42 | set relative position. <4 bytes> |
0x43 | set stepdelay. (in tenths of a millisecond, default 200: 20ms between steps). |
0x44 | Set number of driven coils. Writing 0x00 means driving one coil, other values mean driving two coils |
Simple high-side PWM section.... | |
0x50 | set PWM value for output B1 |
0x51 | set PWM value for output B2 |
0x52 | set PWM value for output A1 |
0x53 | set PWM value for output A2 |
0x58 | set PWM value for all four outputs as a single 32-bit value. |
Read ports
The spi_motor boards defines the following read ports:
port | function |
---|---|
0x01 | identification string. (terminated with 0). |
0x02 | read eeprom (serial number). |
two separate brushed motors section.... | |
0x20 | Read back intensity and direction of motor A |
0x21 | Read back intensity and direction of motor A |
0x30 | Read back intensity and direction of motor B |
0x31 | Read back intensity and direction of motor B |
Stepper motor section.... | |
0x40 | read current position. <4 bytes> |
0x41 | read target position. <4 bytes> |
0x43 | read stepdelay. (in tenths of a microsecond, default 200: 20ms between steps). |
Simple high-side PWM section.... | |
0x50 | get PWM value for output B1 |
0x51 | get PWM value for output B2 |
0x52 | get PWM value for output A1 |
0x53 | get PWM value for output A2 |
0x58 | get all 4 PWM values as a 32-bit value. |
Examples
Read identification
read the identification string of the board. (motor)
data sent | data recieved | explanation |
---|---|---|
0x91 | xx | select destination with address 0x90 for READ. |
0x01 | xx | identify |
xx | 0x73 | 's' |
xx | 0x70 | 'p' |
xx | 0x69 | 'i' |
xx | ... | etc. |
Move stepper to step 0x12345678
data sent | data recieved | explanation |
---|---|---|
0x90 | xx | select destination with address 0x90 for WRITE |
0x41 | xx | port 0x41: set target position |
0x78 | xx | |
0x56 | xx | |
0x34 | xx | |
0x12 | xx |