05-15-2018 07:45 PM
Hello,
I'm using the NI-9402 to communicate to a sensor using I2C, and I'm having trouble writing 8 bytes to the sensor. I'm attaching my block diagram VI.
For this I2C communication, what I want to do is to write:
Slave Address 4C; Write = 0; ACK | 0x0D ; ACK | 0x40; ACK | Repeated Start |
Slave Address 4C; Write = 0; ACK | 0x0F; ACK | 0x42; ACK; Repeated Start |
Slave Address 4C; Write = 0; ACK | 0x20 ; ACK | 0x01; ACK | Repeated Start |
Slave Address 4C; Write = 0; ACK | 0x21; ACK | 0x08; ACK; STOP
However, with the code that I have, I am seeing on the scope:
Slave Address 4C; Write = 0; ACK | 0x0D ; ACK | 0x40; ACK | Repeated Start |
Slave Address 4C; Write = 0; ACK | 0x0F; ACK | 0x42; ACK; STOP
If I stop the program and run again, I see the other two commands:
Slave Address 4C; Write = 0; ACK | 0x20 ; ACK | 0x01; ACK | Repeated Start |
Slave Address 4C; Write = 0; ACK | 0x21; ACK | 0x80; ACK; STOP
I am not able to write 8 bytes of data. I only see either the first 4 bytes or the last 4 bytes. How do I fix this issue? Any help would be appreciated. Thanks.
05-16-2018 06:28 AM
Please post VIs not pictures
05-16-2018 10:56 AM
Is there a specific reason you are using the 9402? If on a PC, it would be A LOT simpler to just use an USB-845X device.
05-16-2018 01:20 PM
Hello, I'm attaching the VI below.
I'm using the cRIO-9039 controller, and the NI-9402 is a module that works with it, so that's why I'm using the NI-9402.
Thanks. Any help would be appreciated.
05-17-2018 06:23 PM
Amy4082001,
Have you tried probing the arrays that go into the For Loops that are writing the data to the I2C functions, and check if you see the same behavior? First portion of the data going in on the first run, and the second portion of the data in the second run?
I would recommend you tackle the problem step by step. Meaning, try sending just one message. If that succeeds, try sending two... and so on. It's definitely easier to understand which the problem might be, than trying to solve a four commands puzzle in one shot.
All the best,
05-17-2018 07:46 PM
Yes, I tried probing, but I'm running in an FPGA/ cRIO-9039 environment, and there's no light bulb to troubleshoot and the probing doesn't seem to work (see the attached pic 1 for what the probing says). The only way for me to troubleshoot is to connect an oscilloscope to the I2C pins.
So far, I've been able to:
What I would like to do is:
05-18-2018 08:06 AM - edited 05-18-2018 08:08 AM
OK...
Initial thoughts (sorry I haven't installed LV 2017 yet so I haven't been able to open the VI you posted) are.
You have a simple process:
1) Initialize I2C Port
2) Configure Port
3) Write Port (Loop N Times)
4) Run ARM Port Function
5) Loop back to Step 2 (M times)
6) Read Port (P times)
I would suggest:
a) making the Configure, looped write and Arm Port function into a subVI for your purposes and add a cluster with only the inpus that you intend to
change.
b) ensuring the I2C reference cluster going through the FOR loop passes round a Shift register.
c) handling errors between calling the subVI, and then running the subVI more times in a for loop (There is no need for all those locals on the clock divider, in fact if you change the input clock divider2, this could be the root cause of you issue.
d) ensuring the IP Port.vi has been run (by flow control) and defined the clock before all of the Configure Ports run (in case that is causing a subtle issue.)
e) checking that you are leaving enough time between sending commands and not encountering an unresponsive/ flow control related issue. (You may just be filling the bus and not allowing time for it to empty before attempting to send the next message.)
James
******* Edit: Scratch the subVI if you are not reconfiguring everytime anymore **************************
05-21-2018 11:43 AM
Hi James,
Thanks for your input. Please note that I am able to write 2 commands so fundamentally, I know the VI is somewhat working (see attached scope pic for the 2 commands that I am seeing). However, the question still is – how do I write more than 2 commands?
I did try your suggestion (e) by:
05-22-2018 02:39 AM
Hi Amy,
Isn't your problem really simple then...
You are sending message n+1 before you've sent the stop for message n. This is confusing the I2C bus and returning the results which you are seeing. If you handle the messages as complete packets from send to stop, you should be fine.
(I don't think you've put your time delay in the correct place) - but I only normally do simple single packet I2C comms when needed.
This seems like it might help:
http://maxembedded.com/2014/02/inter-integrated-circuits-i2c-basics/
But equally you look like you've already read up and covered lots of this already so it's unlikely to be a simple mistake. Sorry if I can't help any further.
James
06-06-2018 07:19 PM
Hello, for completeness, I want to post up my solution (see attached pic) for writing multiple commands from the NI-9402 to a slave (mine was the MC3672). I am still having trouble reading from the slave, but I'll post that in another forum.