Recommended Posts

I am trying to interface with a STM microcontroller via Labjack, I know the I2C works due to testing with an Aardvark. However when I try to send data over the Labjack I am unable to send the data payload. There must be something wrong with my code, but browsing the limited docuemntatyion on the matter yielded little fruit. Any help would be apprictated.

 

Thanks!

My Code:

using("device.labjack.")
try
   include("c:\program files (x86)\labjack\drivers\labjackud.h")
catch()
   include("c:\program files\labjack\drivers\labjackud.h")
endcatch

global ID = 0

ePut(ID, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0)

AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chI2C_ADDRESS_BYTE, 0x62, 0, 0)
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chI2C_SCL_PIN_NUM, 0, 0, 0)
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chI2C_SDA_PIN_NUM, 1, 0, 0)
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chI2C_OPTIONS, 1, 0, 0)
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chI2C_SPEED_ADJUST, 0, 0, 0)

GoOne(ID)

numWrite = 2
array[0] = 0x07
array[1] = 0xd0

AddRequest(ID, LJ_ioI2C_COMMUNICATION, LJ_chI2C_WRITE, numWrite, array, 0)
AddRequest(ID, LJ_ioI2C_COMMUNICATION, LJ_chI2C_GET_ACKS, 0, 0, 0)
GoOne(ID)

Scopeshot of the resulting transaction

image.thumb.png.f47ea73ef947fbfb4b6e1a2c26c5606f.png

Share this post


Link to post
Share on other sites

It looks like your device isn't receiving an "ACK" from your I2C slave sensor so the I2C packet is failing.  Can you double check the slave address and make sure that you have pull-up resistors installed?  In our I2C app-note we recommend 4.7k resistors.  If you haven't already tried switching to the EIO0 and EIO1 ports, please do that as well.  

Share this post


Link to post
Share on other sites

We discussed this issue today as a group and noticed one other potential issue.  It doesn't look like you properly define your "numWrite" or "array" variables.  There is a chance that you could be instructing DAQFactory to write no bytes to the device instead of two.  You can easily test this by modifying the line:

AddRequest(ID, LJ_ioI2C_COMMUNICATION, LJ_chI2C_WRITE, numWrite, array, 0)

to be:

AddRequest(ID, LJ_ioI2C_COMMUNICATION, LJ_chI2C_WRITE, 2, array, 0)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now