I2C Controller
Last updated
Last updated
The Binho Nova Multi-Protocol USB Host Adapter can serve as an I2C bus controller device which can be configured to meet the needs of nearly any I2C bus implementation. The I2C controller supports clock frequencies from 100kHz up to 3.4MHz, which covers all common operating modes (standard, full speed, fast, and high speed modes). The Binho Nova Multi-Protocol USB Host Adapter also features support for clock-stretching and repeated starts. There are internal pull-up resistors which can be programmatically engaged or disabled as necessary.
The I2C pins are fixed - SDA is assigned to IO0 and SCL is assigned to IO2. IO1, IO3, and IO4 are available for use when the host adapter is configured for I2C controller mode.
The following table gives a brief overview of the available I2C controller commands.
Command
Description
Details
Feel free to jump ahead to the ASCII Command Set reference to learn the specifics of each command, or continue below to see an example of how to use these commands to achieve communication on the I2C bus.
I2C CommandsThe first step in using the Binho Nova Multi-Protocol USB Host Adapter as an I2C controller is to put the adapter into I2C mode using the Device Operating Mode command.
Now the host adapter is in I2C communication mode. The next step is to configure the I2C bus. Here are the default settings:
I2C clock frequency = 400kHz
I2C pull-up resistors disabled.
I2C addresses displayed as 8-bit addresses.
Let's change the address display setting to 7-bit so that it matches the manufacturer's datasheet for the device on the bus.
The ADDR setting only modifies how the address is entered/displayed in the serial console. It does not have any effect on the device addressing during I2C communication.
And let's also engage the internal pull-up resistors to eliminate the need for wiring up external resistors.
Before even attempting communication with the peripheral device, let's make sure everything checks out. The address of the target device is 0x50.
Great! The Binho Nova Multi-Protocol USB Host Adapter found the target device on the I2C bus as indicated by the OK
response when scanning it's address. If the addresses of the devices on the I2C bus are unknown, it's possible to scan the entire bus for devices simply by omitting the address from the scan command.
Now it's time to start communicating with the devices on the bus!
Let's begin to define an I2C transaction that will be carried out by the host adapter. Every I2C transaction must begin with a start bit followed by the address of the target device. When performing an I2C Write operation, the START
command must be issued manually:
Now let's queue up a couple of bytes of data to write:
Unlike SPI controller mode, the I2C transactions are only sent out on the bus after sending the END
command. This is great because it means there's no rush to enter data in the serial console when manually interacting with I2C devices.
Requesting data from the I2C peripheral device is also quite simple. When requesting data from the peripheral device, there's no need to manually issue the START
command, it's handled automatically:
Sometimes reading data requires writing a value to a particular location and then sending a repeated start bit to read out the desired value. Here's an example of such a transaction:
It's also possible to write and request data on the I2C bus using the buffer. This can be helpful when writing/requesting more than just a few bytes at a time. Let's use BUF0 to help send 8 bytes on the I2C bus:
The buffer can also be used to receive requested data from the I2C bus as follows:
That's all there is to I2C communication with the Binho Nova Multi-Protocol USB Host Adapter. You can take some time to learn all the details about the I2C commands or skip ahead and look at some of the examples that use I2C in an automated fashion:
ExamplesFor use cases where a lot of data is being read/written and speed is important, the WHR command should be utilized to minimize the amount of communication between the Nova and the host PC. You can learn all the details about this here.
Next up we'll be doing a walk-through using I2C Peripheral.