The Cerebellum Project


[ Home ] [ Up ]

Daughterboard I2C Interface

The I2C protocol shall be the datalink layer for this interface. The cerebellum shall be the I2C master, and the daughterboards slaves.

All data sent from master will be ACK'd by slave. ACK of a byte means byte received, but not action taken. After every command, master has to initiate a read, and read one packet of data from the slave. Each packet will begin with a length byte, followed by the appropriate number of bytes. The first data byte (second byte in the packet) will contain status information regarding actual command completion or any error conditions that might exist. A status byte of zero (0) would mean the command was understood and will be carried out. A non-zero status byte would indicate some form of error.

Prototypical transactions:

Sending data to daughterboard:

Master: <start><slave addr><write>
Slave: ACK
Master: <length>
Slave: ACK
Master: <command>
Slave: ACK
Master: <data1>
Slave: ACK
... as many as necessary ...
Master: <restart><slave addr><read>
Slave: ACK
Slave: <1>
Master: ACK
Slave: <status>
Master: ACK
Master: <stop>
Reading data from daughterboard:
Master: <start><slave addr><write>
Slave: ACK
Master: <command>
Slave: ACK
Master: <restart><slave addr><read>
Slave: ACK
Slave: <length>
Master: ACK
Slave: <status>
Master: ACK
Slave: <reply1>
Master: ACK
... as many as necessary ...
Master: <stop>

From this protocol, all packets (whether from master or slave) start with a length byte, followed by the appropriate number of data bytes.

According to the I2C protocol, if the Master receives a NACK from the Slave, it can either signal a <stop> or a <restart> and abort the transfer or retry respectively. If the Slave receives a NACK from the Master, it should abort, reset itself and wait for a <(re)start>.

Master write commands:

00: motor off
02: engage pwm (open-loop) mode
03: engage pid controller
04: set pwm output
<data1>: dir
<data2>: duty cycle
05: set pid velocity
<data1>: vel
06: reset displacement counter
08: set controller constants
<data1>: Kp
<data2>: Ki
<data3>: Kd

Master read commands:

10: read current velocity
<reply1>: current velocity
11: read current displacement
<reply1>: hi byte
<reply2>: lo byte
12: read controller constants
<reply1>: Kp
<reply2>: Ki
<reply3>: Kd

[ Home ] [ Up ]


Contact: kwanjee@andrew.cmu.edu -- First Edition: 07/27/01 -- Last Update: 08/04/01