Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-9402 I2C Reading Erroneously from a Sensor

Solved!
Go to solution

Hello, I'm using the NI-9402 as an I2C to communicate to a sensor.  Although I am able to successfully write to and read from the sensor, there are runs where the sensor data are shifted.  Here are more information of my system and error:

  1. Sensor output data are read from Register Addresses 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  2. On the first run, the readings are usually correct.  If I stop the VI, re-run, sometimes the readings are correct, sometimes the readings are shifted (see #3). The correct readings from the sensor are as follows:
    • Register 0x02 should read 227 (in decimal code)
    • Register 0x03 should read 255
    • Register 0x04 should read 10
    • Register 0x05 should read 4
    • Register 0x06 should read 30
    • Register 0x07 should read 0
  3. Sometimes the readings from the sensor are shifted.  For example, they show:
    • Register 0x02 now reads 0
    • Register 0x03 now reads 227
    • Register 0x04 now reads 255
    • Register 0x05 now reads 10
    • Register 0x06 now reads 4
    • Register 0x07 now reads 30
  4. I'm attaching the code in VI and PNG.  The code is a little bit redundant and can be optimized, but I'll worry about this later when I get it working.

Any idea what I could try?  Thanks.

0 Kudos
Message 1 of 13
(3,783 Views)

Hey,

 

I do have a few questions in regards to your application:

 

1. What sensor are you using?

2. Are you able to scope the output of your slave device to see if that matches the values you are getting in LabVIEW?

 

Thanks,

 

-Brian J.

0 Kudos
Message 2 of 13
(3,734 Views)

Hi Brian,

I'm using the MC3672 accelerometer. Yes, I'm able to scope the I2C lines and verify that the readings from the sensor are correct.  As mentioned, sometimes Labview report the correct readings; sometimes, Labview reports a shifted reading.

0 Kudos
Message 3 of 13
(3,732 Views)

Hello,

 

So my issue with the 9402/9039 seems to be fixed until I changed its code today.  

 

Yesterday, I wrote some code for the I2C 9402 and my MC3672 sensors. 

  • As reported, after the FPGA compiles, the output from reading 6 registers from the sensor are correct (readings appear in order for registers 1/2/3/4/5/6). 
  • However, if I stop the program, re-run, the output readings are shifted (data sometimes appear for register 6/5/4/3/2/1, or 5/6/4/3/2/1, etc). 
  • Again, when I scope the I2C lines, the data are in the correct 1/2/3/4/5/6 order. 
  • The FPGA "INVOKE METHOD --> RESET" that I included in the cRIO_9039 code (see attached image) seems to correct this problem.

 

Today, I slightly changed my 9402 code to include a two byte write in a while loop. 

  • This time, however, after the FPGA compiles, the output from reading 6 registers from the sensor appear in this incorrect order 6/1/2/3/4/5. 
  • Again, I scoped the I2C lines and confirmed that the sensor are outputting the correct values in the 1/2/3/4/5/6 order.  
  • Running this 9402 code in the cRIO environment and using this "INVOKE METHOD --> RESET" continuously shows the incorrect 6/1/2/3/4/5 order.

I added an image to show the two different 9402 codes.  Hopefully somebody can pick out what I'm doing wrong. Thanks.

0 Kudos
Message 4 of 13
(3,690 Views)

Hello,  I still haven't solved my problem.  But I noticed today that I duplicated the code 4x (because I have 4 sensors), and the output shifts differently for sensor #1 versus the other sensors.  This leads me to think that it's not the Labview code but something in the FPGA (cRIO 9039). Any thought?

0 Kudos
Message 5 of 13
(3,671 Views)

Do you observe this behavior even if you do not read from register 6 (i.e. just read from 5 registers)? What is the value of the "Read Register Start"?

Brian.D
NI Product Owner
VeriStand
0 Kudos
Message 6 of 13
(3,658 Views)

Hello, the value of the "Read Register Start" is 0x02.  

 

Yes, I do observe this issue even if I was reading from 5 registers, or even 1 register.  And this issue also occurred even if my "Read Register Start" is not 0x02.  

0 Kudos
Message 7 of 13
(3,654 Views)

Do you have a manual for the I2C commands? 

 

As a workaround, you could do some array manipulation to change the order you are reading so you actually read in the correct order. It seems that the FPGA Reset keeps the "shifting" behavior consistent.

Brian.D
NI Product Owner
VeriStand
0 Kudos
Message 8 of 13
(3,637 Views)

Hi Brian,

 

What do you mean by I2C manuals?

 

I am currently accepting this "output shift" bug and routing my outputs to the plots accordingly.  Luckily, the FPGA RESET allows the shift to be consistent every time I run the code, so for now, this will be the solution to this bug.  

0 Kudos
Message 9 of 13
(3,627 Views)

By the way, Brian, one of my NI-9402 CH0 just totally died yesterday.  CH0 is consistently outputting 0, and when I scoped the I2C lines, I don't see anything.  I swapped CH0 and with CH1, and I do see I2C communication on CH1 but not CH0, which means my sensor is OK, but something is wrong with the 9402's CH0.  Should I open another ticket to look into this, or how should I debug?

 

Thanks. 

0 Kudos
Message 10 of 13
(3,626 Views)