07-31-2020 03:30 PM - edited 07-31-2020 03:35 PM
Hello,
So at work the goal is to send I2C commands to a Port Expander (PN:MCP23017) but I am completely lost also semi-new to LabView anyways. I understand at a high level what needs to happen in order to write to the Port Expander. Datasheet says I need to first write to it and "Define I/O Direction" then after this is defined I can write to send the actual data.
I downloaded the NI-845x drivers and I have all the I2C vi's available. I'm just so lost on how to actually code this and write anything. I feel like I'm missing an extra write step for defining the I/O direction but I don't know. I keep getting the Error -301742 which says "The slave did not acknowledge an address+direction byte transmitted by the I2C master."
The following is my attempt so far....
Solved! Go to Solution.
08-02-2020 09:47 AM - edited 08-02-2020 10:02 AM
Too bad you're not using a SPI chip. I got introduced to SPI and the 8452 about eight months ago, even used a Port Expander chip (MCP23S17, same as yours but SPI-enabled). Knew nothing about SPI at the time, fortunately had a colleague who "knew more than I" (not that difficult!) who'd made a first pass and got a crude (messy) version of code to work. I basically "cleaned up" his code, asked some Engineers to explain how the Chip worked, and went to town. [Hint -- set up Bank 0 addressing, makes life so much simpler].
For what it is worth, here's how I configured the Chip:
You set up the Chip once, then just use Word or Byte writes, as required. Note that you need to tell the 8452 which SPI chip you are trying to talk to, i.e. you need code to do the Chip Select, but you probably already have that figure out.
For what it is worth, I'm now doing all the SPI stuff in an FPGA (also very new to me) -- very interesting, and a lot more fun.
Bob Schor
P.S. -- I just looked at the I2C examples that ship with LabVIEW. It looks like (if you are only doing Data Out, i.e. setting the Port Expander bits, not using it for input) that General I2C Write has both the (one-time, usually) "initialization" code (where you use all of the blocks) and the later "Write Data to the Register" (where you only use part of the last major block, assuming you've not closed the Reference to the SPI Master and its Slave (the first two blocks).
08-03-2020 08:40 AM - edited 08-03-2020 08:40 AM
@GeneralDynamic wrote:
The following is my attempt so far....
It looks like you are on the right track. As you said, you need to set the port to be an output (defaults to input). Here's what I put together really quick.
NOTE: I barely skimmed the data sheet and have not used this chip. So no promises it works.
Something you might want to consider is making a VI to write to a Register. It can put the register and value into an array and write the I2C message. I have something similar hiding in my libraries.
08-04-2020 10:48 AM
Oh so you think I might have to use 2 write blocks: 1 for defining I/O direction and the other for data.
How come you used different control types for each write?
08-04-2020 10:49 AM
What do you mean the I2C example that ships with LabVIEW? How can I get this?
08-04-2020 11:21 AM
@GeneralDynamic wrote:
How come you used different control types for each write?
For the first one, I hardcoded the direction to be output. For the second one, I was writing a desired value. So basically it was two different situations, so the way I built up the array was different.
08-04-2020 11:25 AM
I just keep getting an error, I feel like I'm so close. Thanks for the help though, I know its hard to troubleshoot this with me when you cant physically see my setup.
08-04-2020 11:30 AM
@GeneralDynamic wrote:
I just keep getting an error, I feel like I'm so close. Thanks for the help though, I know its hard to troubleshoot this with me when you cant physically see my setup.
The error claims in invalid setting. What values values are you using for the device address, address size, and clock rate?
08-04-2020 11:35 AM
Maybe it's easier if you just open up my code? If not let me know.
08-04-2020 12:00 PM
Clock Rate is default to 0. That is likely your problem.