LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

ADXL345 - SPI Interface

Hi all,

I am trying to establish a SPI connection with an Arduino Mega 2560 and multiple ADXL345s. I have sucesfully connected 2 ADXLs through I2C but need  to talk to more than two.

I have not been able to use SPI as a means of communication with the ADXL345.

Would you mind sharing your thoughts on this?

Thanks

Download All
0 Kudos
Message 1 of 6
(7,472 Views)

This, from the ADXL345 data sheet, is what you're currently doing, correct?

"With the SDO/ALT ADDRESS pin high, the 7-bit I2C address for the device is 0x1D, followed by the R/W bit. This translates to 0x3A for a write and 0x3B for a read. An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the SDO/ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read."

I've seen people recommend connecting multiple conflicting I2C devices and simply turn off the conflicting ones during the read, like this:

Cycle 1

0x3A OFF

0x3A READ

0x3B OFF

0x3B READ

Cycle 2

0x3A READ

0x3A OFF

0x3B READ

0x3B OFF

Cycle 3

0x3A READ

0x3A OFF

0x3B OFF

0x3B READ

Which seems to me can be done pretty quickly but that may not work for you.

I found a reference to introducing this multiplexer/demultiplexer: http://www.digikey.com/product-detail/en/CD4052BCN/CD4052BCN-ND/1916

Here is the data sheet: http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/CD4051BC.pdf

I've never done this myself but it seems like the right way to proceed and will probably end up in my current project.

Sorry I don't have a definitive answer for you, I can only try to nudge you in a direction you might not have thought of yet.

0 Kudos
Message 2 of 6
(4,554 Views)

Thanks ChristopherS,

this might be a possible solution but I am not looking into this right now.

Looking at example library of the LabView First Robotics suite, there is an SPI ADXL345 example. Unfortunately, I am not able to open the VI completely due to the lack of the CompactRIO package (and possibly more).

It is not completely clear to me how to use the "SPI Send Receive" VI in the first place. Is it similar to the I2C package?

0 Kudos
Message 3 of 6
(4,554 Views)

lookingforflow wrote:

It is not completely clear to me how to use the "SPI Send Receive" VI in the first place. Is it similar to the I2C package?

There may be abstract similiarities but I wouldn't base any code for SPI on code for I2C.  They are very dependent on the actual communication protocol which I assume you know is quite different.

At first glance, it seems like you are doing things correctly.  However, note that there may be an issue with the SPI part of the firmware as noted in this thread.

Also, please save VIs post here for an earlier version of LabVIEW so that those of us who do not have the latest version can still try to help.  I always save my attachments for 2009.

0 Kudos
Message 4 of 6
(4,554 Views)

Nathan_B.,

sorry for not thinking about the .vi for earlier versions of LV. Here you go.

I have read the thread you pointed at and made adjustments to the firmware. Still, no success.

Does anybody have acces to ADXL345 SPI example file in the First Robotics Package?

0 Kudos
Message 5 of 6
(4,554 Views)

Assuming that there are no more bugs in the LIFA SPI functions, all you need to do is find existing working SPI code (for any platform) to see what settings they use to communicate with it.  Having the FIRST Robotics version won't provide any more information than any other working examples (since it's written for a cRIO).

0 Kudos
Message 6 of 6
(4,554 Views)