From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to format data for I2C basic write?

Solved!
Go to solution

Hello Friends,

 

It is my first time to use USB 8451, a I2C device. I am just playing around to write data to a slave I2C device using the  I2C basic write vi, which is found in program samples and attached here below. 

 

I would like to write a hexadecimal value of "2801" to a register (address is "1A") of the slave I2C device (device address is "2A"). The write sequence shown in the device datasheet is as below. Can someone let me know how to combine address "1A" and data "2801" together for inputting in the front panel's EEPROM data address?

 

edmonton_0-1610165439719.png

 

 

 

edmonton_1-1610165883946.png

 

There is a note in block diagram, I paste it here below, but I do not know how to make it work 

 ----------------------------------------------

The format for many EEPROMs is:
a) The first two bytes or the first byte are the address to write to.
Check the correct endianess for your device to sent in big endian format (MSB first) or little endian format (LSB first).
b) The next x bytes sent to the device are the bytes that are to written to the EEPROM. For this example, we are creating an array of x sequential bytes (0, 1, ...) up to the number of bytes to write. Many EEPROMs, when they exceed the page size will simply begin to
write at the beginning of the page boundary, thus the write must be split into page aligned writes.

-------------------

 

Thanks,

Gu

0 Kudos
Message 1 of 6
(2,479 Views)

For writing a 16-bit value to a register, you use Split Number to break up the U16 value into 2 U8 values (MSB and LSB).  You then use Build Array to combine the register address, MSB, and LSB into an array that you can then wire up to the I2C Write function.

NOTE: Notice the radix is visible for all of those numerics and they are set to Hexidecimal display.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(2,432 Views)

Hi Crossrulz,

 

Thank you very much for your effort. 

I modified the write vi according to your suggestion and added a read vi to read the written value back to see if the written value is correct. The read value shows 0,0 rather than 28,01. 

 

The read vi is also found from the LabVIEW program samples, which I verified to work properly. 

Both write & read VIs are attached here below.

 

Could I trouble you to check anything wrong?

 

Thanks,

Gu

 

Download All
0 Kudos
Message 3 of 6
(2,419 Views)
Solution
Accepted by topic author edmonton

The problem I have with many NI examples is they try to do too much.  Simplification often helps a lot more here.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 6
(2,405 Views)

Hi Crossrulz,

 

Thanks. It worked. I think that the Write VI of the sample program should have had writing a register with a value rather than  just a register alone without a value. 

 

In addition, I have searched on the community forum about the USB 8451 I2C, and found an old post,  saying the maximum speed of reading data was 400 samples per second via a loop.  However, the 8451 has a clock speed range of 32-250 kbit/s.

 

8451 I2C Loop Running Slowly When Reading Data

 https://forums.ni.com/t5/LabVIEW/8451-I2C-Loop-Running-Slowly-When-Reading-Data/td-p/2130782

 

My question: Does the USB 8451 really a hardware-timed device?

 

Regards,

Gu

 

 

0 Kudos
Message 5 of 6
(2,392 Views)

The protocol part is hardware timed.  But when those messages are performed is software timed when using the I2C Basic API.  You could try using the I2C Scripting API, but I have no experience using it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 6
(2,379 Views)