F28069M+Sensors BoosterPack I2C R/W Example

Jeff Liu_20693
Jeff Liu_20693 Altair Community Member
edited October 2023 in Community Q&A

Hi,

I am trying to communicate with an i2c device BMI160 on the Sensors BoosterPack by using F28069M LaunchPadXL. And I find there is an example named eepromReadWriteF28027, but it's doesn't work even I set CPU to F28069M. I am new to I2C field, is there any easy Embed example that can work properly to communicate between BMI160 and F28069M for reference?

p.s. the attachment program is modified from the example 「eepromReadWriteF28027」, what I need to do is to read gyro readings from BMI160, the program can run, but the readings don't change when I move or shake LaunchPad.

Thanks! Jeff

Best Answer

  • Peter Darnell
    Peter Darnell
    Altair Employee
    edited October 2023 Answer ✓

    Hi Jeff, I got my Bosch BMI160 sensor board to play with and fixed a few things in the last diagram I sent. This one reads both Gyro and Accel. Enjoy!

    image

Answers

  • Peter Darnell
    Peter Darnell
    Altair Employee
    edited May 2023

    Hi Jeff,

    A couple points: 1) start Tx and start Rx are nonblocking, so you have to wait for the Tx to finish before you Rx and vice versa. It helps to use a state chart which I did in the attached file

    2) You must buffer up the bytes you want to send before enabling the start TX. The Visual RTOS interrupt handler will send out the bytes according to the byte count set in the "start TX" block.

    3) You shouldn't do I2C reads until the read data is available in the read queue. There is a block to tell you how many bytes are in the read queue. (see attached)

    Disclaimer, I don't have a BMI160 to test with (just yet), but this diagram should point you in the right direction.

    Pete

  • Peter Darnell
    Peter Darnell
    Altair Employee
    edited October 2023 Answer ✓

    Hi Jeff, I got my Bosch BMI160 sensor board to play with and fixed a few things in the last diagram I sent. This one reads both Gyro and Accel. Enjoy!

    image

  • Jeff Liu_20693
    Jeff Liu_20693 Altair Community Member
    edited May 2023

    Hi Jeff, I got my Bosch BMI160 sensor board to play with and fixed a few things in the last diagram I sent. This one reads both Gyro and Accel. Enjoy!

    image

    Hi Peter,

    Thanks for your help, I've tried to use this attachment, but still encounter some problem. When I Complile the program, there are some error (attached 1), then I check the C program that created by using Code Gen, the I2CCNTA becomes I2CCNT? Both on line 292 and 360 (attached 2 and 3). I would want to know which Embed version do you use? I've tried Embed 2021.1 and 2022.2 64-bit, they both have same errors, or this is not the version problem?

    Thanks! Jeff

    1.png 53.4K
    2.png 14.8K
    3.png 12.9K
  • Jeff Liu_20693
    Jeff Liu_20693 Altair Community Member
    edited May 2023

    Hi Jeff, I got my Bosch BMI160 sensor board to play with and fixed a few things in the last diagram I sent. This one reads both Gyro and Accel. Enjoy!

    image

    Hi Peter,

    I find the problem and fix it, now the program can successfully build. The figure 1 is your I2C Start Communication Properties, and the figure 2 is mine. I don't know why there are 3 input pins, I can only set 2 input pins the most, enable and data length, and I can't set Data Length Dynamically (it will cause build error like previous reply). So I fix the data length set in the properties block, and remove the third input pin with all of the Start Communication Properties blocks in my program (just like figure 2).

    Now I can build it, but when I run in debug mode (the process is select Read BMI160 Gyro block, Tools→Code Gen→check Use selected compound edge pins for data exchange→Complile→Quit→and GO), the readings of all are still zero (figure 3).

    Can you help to see the problem, thanks for your assistance.

    Jeff

    1.png 7.6K
    2.png 6.3K
    3.png 84.6K