06-10-2009 04:54 PM
*THIS IS A REPOST BECAUSE I ACCIDENTALLY PLACED THIS IN THE LABVIEW FORUM THE FIRST TIME*
Hey everybody,
I'm having some issues getting the USB 8451 to work properly. I currently have connected a MEMS accelerometer using I2C and I'm trying to simply read the WHO_AM_I register to make certain everything is working properly.
The address for this device is 19 (hex) while letting the software take care of the final bit for write/read.
The clock rate is set to 100 kHz.
The WHO_AM_I register is 0F, but the generic I2C Read.vi won't allow that value. When I run the VI, I don't receive any errors. I have had errors before that were quite clear (lack of bus seizure, improper address, etc.). Can anyone help explain why I can't modify this file at all or point me towards a more in depth and robust Read/Write VI? .
When I open up the Write Read.vi that is part of the larger sample VI, I notice the number of bytes to read is set to 0. When I change it to anything other than 0 and run, I receive the error code -301742 in the error out window. I have no idea how to diagnose this because no text accompanies the error message. Thanks for your time
=Chris
Accelerometer Datasheet
06-11-2009 02:18 PM
Chris,
The number of bites to read is 0 in the Write Read VI because that is the default. When you wire a numeric control to the "num bytes to read" terminal on the Write Read VI, it passes that value to the subVI at runtime.
For I2C, you need to specify a starting address of your MEMS accelerometer and also the address of your register right shifted. Take a look at this VI that I have modifed to what I believe will work for your application. The only parameter I think may need tweaking is the Starting Address.
Best regards,
06-11-2009 04:23 PM
Ben,
Thanks for putting that together. Unfortunately, I am still having issues. The address of the device is 19 (after the right shift). This address worked in the general read VI.
The WHO_AM_I register should return 110010 (32h or 50 base 10). The only thing that is returned is 0 regardless of the address.
I have selected my device, set the "Address of Register" to the I2C address of the accelerometer (I believe this is mislabeled).
The clock rate is 100 kHz.
I have set the number of bytes to read at 8 (in the event that this was meant to be bits)
The "Starting Address of MEMS Accelerometer" is set to 15 (the register address of WHO_AM_I - mislabeled with the Address of Register).
The read data just shows lists of zeroes. Any ideas as to what is happening?
=Chris
06-23-2009 02:16 PM
The first image isa picture of what I see with proper I2C protocol. The VI runs without any errors.
When I change the value in "Starting Address of MEMS Accelerometer", the read data continues to show zeroes the whole time.
If I change the value in "Address of Register" to anything other than 19, I receive the error picture attached.
Does anyone have any ideas why this isn't working?
=Chris
06-24-2009 05:35 PM
I would like to point out that the VIregisterchange.JPG and VIaddresschange.JPG actually show expected behavior, whereas the VInoerrors.JPG should actually return 32h. In the VIregisterchange.JPG, you were reading a register (CTRL_REG5, 24h) that has a default value of 0 according to the datasheet, so reading 0 is expected. For the VIaddresschange.JPG, you will need to keep the address of register at 19h as this is the starting address of the device. (You have the Starting Address and Address of Register swapped, I may have swapped these in my first post). This will throw an error if it can't find the device.
Not sure why reading the WHO_AM_I register (0Fh) returns 00 however.
06-24-2009 06:10 PM
I suppose I should have checked that first. This issue is that the regardless of the value of the register, I am reading 0s. I tested every register and the values never change. Have you seen anything like that?
=Chris