Understanding the RoboRio to I2C Interface Design - MDHSRobotics/TeamWiki GitHub Wiki

Home / Tutorials / [How to Use Arduino to Extend RoboRio](How to Use Arduino to Extend RoboRio)

#Understanding the RoboRio to I2C Interface Design

###Introduction The I2C interface is a serial digital interface that enables communication between devices. Devices can either me master or slaves. The master is typically some kind of a controller. In our case, the RoboRio is the master. The slaves are often sensors or actuators. Some sensors and actuators are available as I2C slave devices. There are cases when a sensor is not compatible with RoboRio analog and digital IO pins and are not available as an I2C device. One such example is the HC-SR04, a distance sensor. In these cases, an Arduino or other controller can be configured as an I2C slave and manage the interface to the device. This capability greatly increases the options of sensors and actuators that can be used with the RoboRio.

###Communication The communication between the master and the slave is initiated by the master.
The master sends a message to the slave. The message can either be a request to read a specific register or to write to a specific register.

#####Reading Data from the Slave When the master wants to read data from the slave, it sends a message to the specified slave with 1 byte indicating the the address within the register to read from. Read Message Format

#####Sending Data to the Slave When the master wants to send data to the slave, it sends a message to the specified slave that includes the address in the register that it wants to write to and the data that it wants to write to that location. Using this scheme, a master can send a command to the slave to do something, like move and actuator, collect a reading, or change the configuration of the slave. Write Message Format

#####Register Design As mentioned above, the key to interfacing with I2C devices is to read and/or write to the interface register. The specific interface design varies from application to application. In the base I2CArduino project, the design of the interface is as follows:

I2C Register Design

The structure is typical and is considered best practice:

  • Device Status - The first register location is 2 byte register that enables the I2C device to communicate to the master it's current state, e.g. reading available, disabled, etc.
  • Data - the next register locations are the data registers that hold values that the master should read from the slave, for example, readings from a sensor. There can be as many data registers as needed for the application at hand. The I2CArduino project starts with 2 data registers of 2 bytes each.
  • Mode - the next register location is the mode register. This register location can be used by the master to influence the behavior of the slave device. The I2CArduino project starts with a 6 byte mode register.
  • Config - the next register location is the config register. This register location can be used by the master to configure the slave device. The I2CArduino project starts with a 6 byte config register.
  • ID - the last register location is the identify register. This is typically a 1 byte register. This register location holds an agreed upon ID that identifies the slave device to the master. This is important as the master needs to know who it is talking to. Devices on a bus need to be configured with different addresses.