Difference between revisions of "DIO protocol"

From BitWizard Wiki
Jump to navigation Jump to search
Line 46: Line 46:


{| border=1
{| border=1
! port !! function
!rowspan="2"|port !!colspan="4"|available on !!rowspan="2"|function
|-
|-
! DIO !! 3/7FETs !! RELAY !! pushbutton
| 0x01 || identification string. (terminated with 0).
|-
|-
| 0x01 || X || X || X || X || identification string. (terminated with 0).
| 0x02 || read eeprom (serial number).
|-
|-
| 0x02 || X || X || X || X || read eeprom (serial number).
| 0x10 || read all inputs
|-
|-
| 0x20 .. 0x27 || read one input (0x20 for input 0, 0x21 for input 1 etc)
| 0x10 || X || || || X || read all inputs
|-
|-
| 0x20 .. 0x27 || X || || || X || read one input (0x20 for input 0, 0x21 for input 1 etc)
| 0x40 || read current position. (only DIO and 7FETS)
|-
|-
| 0x40 || X || X || || || read current position.
| 0x41 || read target position. (only DIO and 7FETS)
|-
|-
| 0x41 || X || X || || || read target position.
| 0x43 || read stepdelay. (in tenths of a microsecond, default 200: 20ms between steps). (only DIO and 7FETS)
|-
|-
| 0x43 || X || X || || || read stepdelay. (in tenths of a microsecond, default 200: 20ms between steps).
| 0x50 || Return PWM value for output 0 (only works on dio software version 1.1 and higher)
|-
|-
| 0x50 || v1.1 and up || X || || || Return PWM value for output 0
| 0x51 || Return PWM value for output 1 (only works on dio software version 1.1 and higher)
|-
|-
| 0x51 || v1.1 and up || X || || || Return PWM value for output 1
| 0x52 || Return PWM value for output 2 (only works on dio software version 1.1 and higher)
|-
|-
| 0x52 || v1.1 and up || X || || || Return PWM value for output 2
| 0x53 || Return PWM value for output 3 (only works on dio software version 1.1 and higher)
|-
|-
| 0x53 || v1.1 and up || X || || || Return PWM value for output 3
| 0x54 || Return PWM value for output 4 (only works on dio software version 1.1 and higher)
|-
|-
| 0x54 || v1.1 and up || X || || || Return PWM value for output 4
| 0x55 || Return PWM value for output 5 (only works on dio software version 1.1 and higher)
|-
|-
| 0x55 || v1.1 and up || X || || || Return PWM value for output 5
| 0x56 || Return PWM value for output 6 (only works on dio software version 1.1 and higher)
|-
|-
| 0x56 || v1.1 and up || X || || || Return PWM value for output 6
| 0x5f || Return PWM mask. PWM is enabled on the outputs, who's bit is high. send 0x01 as data, to enable PWM on output 0 (only workson dio software version 1.1 and higher)
|-
| 0x5f || v1.1 and up || X || || || Return PWM mask. PWM is enabled on the outputs, who's bit is high. send 0x01 as data, to enable PWM on output 0
|}
|}



Revision as of 17:37, 12 November 2012

Introduction

The protocol for the DIO, 3FETs and FETs will be explained on this page. Most functions apply to all three boards, but some don't.

This page describes both the SPI and the I2C version. See SPI versus I2C protocols for the explanation about how the protocols work in general.

The default address of the DIO board is 0x84. The default address of the 7FETS board is 0x88. The default address of the 3FETS board is 0x8A.

write ports

On the DIO and related boards all ports just set a single value. So writing more than one byte to such a port is redundant. The last value is the one used. The DIO boards don't have any ports that are logically a stream of bytes. So writing more than one or two bytes is not encouraged.

The DIO, 3FETS and 7FETS boards define several ports:

port available on function
DIO 3/7FETs RELAY pushbutton
0x10 X X X set all outputs (bit 0 is output 0, etc).
0x20 .. 0x27 X X X set one output (0x20 for output 0, 0x21 for output 1 etc)
0x30 X X X define pins as inputs or outputs. 0 means input, 1 means output.
0x40 X X set current position.
0x41 X X set target position.
0x42 X X set relative position.
0x43 X X set stepdelay. (in tenths of a microsecond, default 200: 20ms between steps).
0x50 .. 0x57 v1.1 and up X Set PWM value. 0x50: output 0, 0x51 output 1 etc.
0x5f v1.1 and up X Set PWM mask. PWM is enabled on the outputs, who's bit is high. send 0x01 as data, to enable PWM on output 0
0xf0 X X X X change address.

All the above ports are read/write. I.e. if you read from that port, you will get the current value.

read ports

The DIO, 3FETS, and 7FETS boards support the following read ports:

port available on function
DIO 3/7FETs RELAY pushbutton
0x01 X X X X identification string. (terminated with 0).
0x02 X X X X read eeprom (serial number).
0x10 X X read all inputs
0x20 .. 0x27 X X read one input (0x20 for input 0, 0x21 for input 1 etc)
0x40 X X read current position.
0x41 X X read target position.
0x43 X X read stepdelay. (in tenths of a microsecond, default 200: 20ms between steps).
0x50 v1.1 and up X Return PWM value for output 0
0x51 v1.1 and up X Return PWM value for output 1
0x52 v1.1 and up X Return PWM value for output 2
0x53 v1.1 and up X Return PWM value for output 3
0x54 v1.1 and up X Return PWM value for output 4
0x55 v1.1 and up X Return PWM value for output 5
0x56 v1.1 and up X Return PWM value for output 6
0x5f v1.1 and up X Return PWM mask. PWM is enabled on the outputs, who's bit is high. send 0x01 as data, to enable PWM on output 0

examples

For SPI in the examples below, "data sent" means the data on the MOSI line, while "data received" means the data on the MISO line. when MISO reads "xx" you should ignore the data. When MOSI reads "xx" it doesn't matter what you send.

For I2C in the examples below, you should first initiate a "write" transaction with the data in the "data sent column". Don't send the "xx" bytes. Then you initiate a "read" transaction, and you will get the data in the "data received" column (and again not the "xx" bytes).


read identification

read the identification string of the board. (SPI_DIO)

data sent data received explanation
0x85 xx select destination with address 0x84 for READ.
0x01 xx identify
xx 0x73 's'
xx 0x70 'p'
xx 0x69 'i'
xx ... etc.

read the identification string of the board. (I2C_DIO)

I2C master I2C slave (i2c_dio) explanation
START -- start I2C transaction
0x84 -- select destination with address 0x84 for write (set port).
0x01 -- identify
STOP -- terminate I2C transaction.
START -- start I2C transaction
0x85 -- select destination with address 0x84 for READ.
-- 0x69 'i'
-- 0x32 '2'
-- 0x63 'c'
-- ... etc.

Note that in the SPI example, there is bidirectional datatransfer on every cycle, but the data is "don't care" or "must ignore" (indicated by xx), while in the I2C case, the other side cannot send as there is only one data-transfer direction (indicated by "--").

turn on all outputs

data sent data recieved explanation
0x88 xx select destination with address 0x88 for WRITE
0x10 xx set outputs as in bitpattern (next byte)
0xff xx All outputs active.

turn on output 4

data sent data recieved explanation
0x88 xx select destination with address 0x88 for WRITE
0x24 xx port 0x24: output 4...
0xff xx ... active.

move stepper to step 0x1234

data sent data recieved explanation
0x88 xx select destination with address 0x88 for WRITE
0x41 xx port 0x41: set target position
0x34 xx low byte
0x12 xx high byte.