Jump to content
  • 0

ADXL345 with SPI and LabView


canye23

Question

 

Hello, 

 

I am trying to get x,y,z axis data from the accelerometer adxl345 using linx in labview. I have managed to do that with I2C protocol, but I want to do it also with SPI protocol in order to achieve greater sampling rate. I have read the adxl345 datasheet but I struggle figuring out to which exact registers I must write so that I can read the datax,y,z registers. 

I attach my -so far now working- program below, thank you in advance.

adxl345spi.vi

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

Hi @billskar23,

The Pmod ACL here uses the adxl345.  Here and here are forum threads that might be helpful. Here is an instructable on how to use spi in the linx platform. Here is spi open.  Here is the plug and play instructable for linx.    Here is another instructable using the Pmod ACL.  Unfortunately, both of the instructables use the Pmod ACL in I2C and not SPI.  Here is the adxl345 datasheet. On page 23 is the register map table.  Page 15 describes how to use the spi communications.  Clearing the SPI bit (Bit D6) in the DATA_FORMAT register (Address 0x31) selects 4-wire mode.

cheers,

Jon

 

Link to comment
Share on other sites

So all i have to do is to get the example of the pmodcl2 and change the values of write function in pmodacl2 open ? To be more specific do I need to set the 7th bit of DATA_FORMAT register to 1 to achieve 4-wire communication(which I have) and to set the 4th bit of register POWER_CONTROL for the adxl345 to start measuring?

And the next step is to reduce by 2 bits the data in send receive function in pmodcl2 read function ? 

Link to comment
Share on other sites

Hello @canye23,

Are you working on using the Pmod ACL (that uses the ADXL345) or the Pmod ACL2 (which uses a ADXL362)? I don't believe the Pmod ACL2 has a DATA_FORMAT register, so I will presume you meant the Pmod ACL.

If you are wanting to use the SPI communication, page 15 of the datasheet says SPI communication is automatically enabled when the chip select line is pulled low; otherwise if the chip select line is left or pulled to a logic high, I2C will be used instead. If you want to use 4 wire SPI, you will need clear bit 7 in the DATA_FORMAT register to achieve 4-wire communication as described on page 26. You will need to set the 4th bit of the POWER_CTL in order to put the chip into measurement mode.

I'm not sure what you mean by your next step that you proposed with regards reducing the data by 2 bits in the send receive function. I don't have LabVIEW 2016 (I have LabVIEW 2014) so I'm not able to open your VI and view it for myself.

Thanks,
JColvin

Link to comment
Share on other sites

Dear JColvin,

Thank you for your reply,

Firstly I use 4-wire connection. I have read the datasheet and of course you are right I have to set/clear those bits on the two registers DATA_FORMAT and POWER_CONTROL.

I have tried to do that, but I only get the numbers which you can see and my front panel screenshot. I also attach the block diagram screenshot. If you need, I can attach the vi in an oolder version but it will take some time so I  will do it if you find it necessary. 

blockdiagram.PNG

frontpanel.PNG

Link to comment
Share on other sites

Hi @canye23,

I'm taking a look into this. Your initialization looks correct, but I'm thinking the conversion into physical data (you are using the same method that is used in our own VI blocks and I imagine you got it from there) seems strange and probably incorrect based on unit analysis. I'm seeing if I can create a SPI version on my own to make sure the data makes sense.

Thanks,
JColvin

Link to comment
Share on other sites

Thank you very much for your time, I would be grateful If you could come up with a solution or any further advice on my problem. I am really struggling the last week doing this and if my initialization is correct and do not know what causes the problem.

Link to comment
Share on other sites

Hi @canye23,

Unfortunately I have not found a solution as of yet. I learned that to read over SPI you need need a high bit in the initial transfer, but I was not getting correct data. I then attempted to read the device id, but am reading the incorrect value based on the datasheet so I am looking further into this when I have the opportunity to see what the problem might be.

Thanks,
JColvin

Link to comment
Share on other sites

Yes, that is correct; the reason for this (which isn't very well noted in the datasheet) is that there is a R/W bit in the first byte that sends what address you want to interact with, where a read command needs this bit (the MSB of that byte) to be logic high. This is explained/shown a little bit on page 15 and 16 of the datasheet. I2C already does reads and writes inherently within the protocol itself so it's LabVIEW code does not explicitly call out this necessary action for the ADXL345.

Thanks,
JColvin

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...