-
Notifications
You must be signed in to change notification settings - Fork 0
I2C Slave Lib API
Chip Perason edited this page Nov 29, 2014
·
6 revisions
The I2C_Slave_lib is an interrupt driven I2C Slave. The state machine like code is designed to automatically receive an incoming message into its i2c_buffer_in and record the number of byte received.
The interrupt service then disables itself to prevent the buffer from being overwritten while the application program reads the buffer.
After reading the buffer, the application program re-enables the interrupt service.
Prep: In i2c_slave.asm, set SLAVE_ADRS to a valid 7 bit I2C address.
i2c_error Cleared on Slave address match.
I2C_ERROR_NONE No errors.
I2C_ERROR_OV Overflow on input buffer. Last byte in buffer is
overwritten.
i2c_status
I2C_STATUS_IDLE Awaiting to be addressed.
I2C_STATUS_RECEIVING Incoming message being received.
I2C_STATUS_MSG_RCVD Rec'd message in buffer. Blocks until read out.
Call i2c_slave_init after reading buffer.
I2C_STATUS_SENDING Outgoing message being sent.
i2c_buffer_in
Receiving buffer.
i2c_buffer_in_cnt
Number of bytes in the i2c_buffer_in buffer.
Functions
i2c_init_slave
Initialize the TWI hardware to support I2C Slave interface. This needs to
be called once.
input reg: none
output reg: none
i2c_slave_init
Initialize the TWI for SLAVE I2C interface to receive data. This is
called to prime the Slave to receive data.
The interface will be disabled after receiving a message to prevent
overflow.
input reg: none
output reg: none
i2c_iter
This is the I2C Slave interrupt service routine. It is enabled by the
i2c_slave_init() call and disabled when a message is received.
i2c_status indicates the state of the function.