LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NI8451 I2C with TCA6408

Solved!
Go to solution

Hello,

 

I'm currently working with NI USB-8451 in order to communicate with I2C target (TCA6408ARGTR). I'm working with CVI labwindows. I'm new to I2C so i'm struggling a bit. 

In the TCA6408ARGTR's datasheet, I've found that the address is 0x20 and there are 4 registers. I want to control the output P4 and P5, so I assume that I have to send 0011 0000 to register 1 and 1100 1111 to register 3 as per the datasheet.

 

So first, I've watched the different examples in CVI and I've tried to replicate the logic: 

  • Open communication with ni8451 
  • Open a script configuration
    • set the clock to 100khz
    • set the address to 0x20 as per the target datasheet ans schematic
    • write the start bit
    • write the ADDRES + write
    • write the data => How to select the correct register?
    • write the stop bit
  • Close the script
  • Close the communication with the ni8451

I've tried with the I2C script write example but nothing work. I think I have the right address since I don't have any errors, so I assume that the 8451 receives an ACK from the target.

I would be happy if someone can help me.

 

Edit: I forgot to say that I have a 10k pull up resistor for each SDA and SCL line

 

 

0 Kudos
Message 1 of 3
(166 Views)

You most likely want to change this:

 

	ni845xI2cScriptOpen(&scriptHandle);
	ni845xI2cScriptClockRate(scriptHandle,100);
	ni845xI2cScriptIssueStart(scriptHandle);
	ni845xI2cScriptAddressWrite(scriptHandle, (uInt8)(0x20 & 0x7F));
//	ni845xI2cScriptWrite(scriptHandle,sizeof(buffer[0]),&buffer[0]);
//	ni845xI2cScriptWrite(scriptHandle,sizeof(buffer[1]),&buffer[1]);
	ni845xI2cScriptWrite(scriptHandle,2,&buffer[0]);
	ni845xI2cScriptIssueStop(scriptHandle);
	ni845xI2cScriptRun(scriptHandle, deviceHandle, 0);
	ni845xI2cScriptClose(scriptHandle);

 

The main reason being that you want to have the two bytes transferred as one I2C transaction and not two!

 

But why are you even using the script API? It would be easier to simply use the Basic API.

Rolf Kalbermatter
My Blog
Message 2 of 3
(121 Views)
Solution
Accepted by topic author Dorifuta

Hello,

 

Thanks for your answer. I worked a bit on it yesterday, and apparently the I2C is not the issue. In fact, I was thinking that the I2C was not working because I'm new to it, and it was a simpler solution to say that I was at fault instead of the PCB.

But after some test, I figure that the output changes correctly when I send an I2C command. So my script was not the problem, I just panicked for nothing.

I used the script API, but I've also tried the basic API with the same outcome.

Anyway, thanks for your time. 

0 Kudos
Message 3 of 3
(114 Views)