How do I read from a specific register on a slave device using I2C communicating with a C2000 / F2803x device with Embedded Coder?

5 views (last 30 days)
I am trying to read specific registers on a slave device using I2C on a C2000 device. I tried to do this by copying the "Using the I2C Bus to Access Sensors" (c28x_i2c_sensor) example available at the following link:
But when I do that, the output of the I2C Receive block is all 0.
How do I read values from the registers on my device using the I2C protocol?
 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Oct 2021
Edited: MathWorks Support Team on 7 Oct 2021
If you have this issue, please refer to the attached model.
The important difference between this example and the one linked in the question is that after transmission, you must check that the I2C is ready after before the I2C Receive block is executed. Not waiting is what causes the output to be 0.
In this model, the subsystem "c2000_i2c_sensor_hub_booster/First time only Initialization" is run at initialization, and is specific to the Sensor Hub Booster Pack, and may not be necessary for your use.
The subsystem "c2000_i2c_sensor_hub_booster/Always running after init Read Accelerometer Data/I2C register read" is the system in which you will be most interested. It contains the logic for first sending the register address to read from (using Slave address register 104 specified in the dialog), waiting for I2C to be ready, and then reading the specified registers from the slave. This aligns with the protocol described in the following document:

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!