WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

I2C Slave

Allows your board to become an I2C Slave that can be called by an I2C Master board.
A slave can only talk when it is asked a question and must therefore listen for incoming messages to which it can reply with a response.
Project Designer allows you to set a unique I2C address for your board as well as defining the message size for incoming requests and outgoing responses.
WebbotLib allows you to define two functions in your code: a 'receive handler' and a 'transmit handler'.
When a master sends you a message WebbotLib will then call your 'receive handler' passing a pointer to the received message. You can then act upon what you have been asked to do - but you cannot send back any response yet.
If the master is expecting a response then WebbotLib will eventually call your 'transmit handler' allowing you to write your response into a buffer that WebbotLib will send back to the master.
Project Designer autonmatically adds the handlers to your main file and they look like this:
// A message has been received from an I2C master
void I2cSlave::receiveHandler(cBuffer* rx){
/* add code here to parse the message */
}
// Send response to the previous message
void I2cSlave::transmitHandler(cBuffer* tx){
/* add code here to write it out */
}
Function Summary

Valid XHTML 1.0 Transitional