BBB SPI//ADXL375

I am working on a design project involving a BeagleBone Black and an ADXL375 Accelerometer.

Per the data sheet (attached), in order to enable the maximum sampling rate of the ADXL375, I need my BBB to communicate with the ADXL375 over SPI (I2C is not fast enough for this).

I have used the Adafruit library for I2C just to test the functionality of the ADXL375, and I can confirm that the accel. does in fact work. However, I am unsure of how to even perform a simple read of the ADXL375 DEVID register using SPI. I have included my steps for how I think a read should be performed, but I suspect that this process is incorrect as I get no output.

I am using the Adafruit BBIO library which I understand is just a python wrapper for the file spimodule.c. All of this is available here:

https://github.com/adafruit/adafruit-beaglebone-io-python/

Based on that code, I am not sure if I will need to hold CS low using one of the methods/variables of an SPI object or if the writebytes()/readbytes() methods take care of this for me. In other words, I don’t know if I should be doing something like

spi.cshigh = low
spi.writebytes([list])
spi.readbytes(numBytes)

OR if I can just do

spi.writebytes([list])
spi.readbytes(numBytes)

Process for reading from SPI (from python terminal):

from Adafruit_BBIO.SPI import SPI

#using SPI bus 0 on P9 of BBB, assuming i’m using dev0, not really sure how to determine this, but I have no other peripherals connected
spi = SPI(0,0)

#set desired frequency, 2MHz
spi.msh = 2000000

#per the ADXL375 datasheet, when performing a read, need to send a byte where bits 0-5 are address bits (DEVID register is 0x0), bit 6 is a multiple bytes bit (for reading/writing multiple bytes), and bit 7 is a read/write bit where read is ‘1’ and write is ‘0’

#so I use 0b10000000 or 0x80 and call writebytes
spi.writebytes([0x80])

From here I receive no output, even if I do spi.readbytes(1), I get [0] back.

I have a pretty good understanding of Linux, Python, C, and the concept of SPI seems simple enough, but this is my first experience with a BBB. I feel like I am missing something simple like setting CS low, which I don’t think is very clearly documented in the attributes for the SPI library.

Here is some info about my BBB:
lsb_release -a
Distributor ID: Angstrom
Description: Angstrom GNU/Linux v2012.12 (Core edition)
Release: v2012.12
Codename: Core edition

uname -a
Linux beaglebone 3.8.13 #1 SMP Wed Sep 4 09:09:32 CEST 2013 armv7l GNU/Linux

I have also attached the breakout board user guide for the ADXL375. I would be happy to come back with any additional info.

Thanks,
Stuart

ADXL375.pdf (509 KB)

EVAL-ADXL375_User_Guide.pdf (87.7 KB)

Hello Stuart, I've been using BBB to communicate with another Analog
Devices device (ADE7753) , and I can confirm you that it works.
Have you tried to do a loopback test before connecting the ADXL275?
Just use a wire in the BBB to join DI and DO in P9, and run this
program:

from Adafruit_BBIO.SPI import SPI

spi = SPI(0,0)
spi.mode=2

spi.msh=2000000
spi.open(0,0)

print spi.xfer2([32, 11, 110, 22, 220])
spi.close()

You should see 32,11,110,22,220 in your terminal as it's returned by
the spi instruction.

You don't need
spi.cshigh = low
because that's its default value.

If the loopback test works, then you can try with the device. I can
confirm you that using ADE7753 and adafruit python library I have need
some time to get it working, until I found out the trick.

Regards.
José L.

Hi Jose,

I finished this project a couple of weeks ago.

I wanted to thank you for getting back to me with such helpful information, and I also wanted to follow up with my solution to the SPI problem (for future users).

I ended up using a different driver file for SPI0 than the one provided by Adafruit:

http://elinux.org/BeagleBone_Black_Enable_SPIDEV

Guide for adding SPI driver:

http://stackoverflow.com/questions/21276090/beaglebone-black-enable-spi-interface

For me, the easiest method for verification was to read the DEVID register on the accelerometer.

#python code:
print spi.xfer2([0x80,0x00])

This prints a list of 2 bytes. With how I understand SPI to work, the second byte in the printed list should always be the DEVID. The first byte may or may not be the DEVID. This is just one of the nuances of the data flow of SPI.

-Stuart

Hi Jose,

I finished this project a couple of weeks ago.

I wanted to thank you for getting back to me with such helpful information,
and I also wanted to follow up with my solution to the SPI problem (for
future users).

Great

I ended up using a different driver file for SPI0 than the one provided by
Adafruit:

BeagleBone Black Enable SPIDEV - eLinux.org

Guide for adding SPI driver:

beagleboneblack - Beaglebone Black - Enable SPI Interface - Stack Overflow

I'm not using adafruit library anymore. It doesn't work with newest
kernels, so I had to use another one.

For me, the easiest method for verification was to read the DEVID register
on the accelerometer.

python code:
print spi.xfer2([0x80,0x00])

This prints a list of 2 bytes. With how I understand SPI to work, the second
byte in the printed list should always be the DEVID. The first byte may or
may not be the DEVID. This is just one of the nuances of the data flow of
SPI.

I think it's not a spi fault but a combination of spi and the way
Analog Devices set it up .

Thanks for your advices and confirmation.

José L.

I am trying to communicate between BBB and ADE7880 using SPI. But on spi.xfer2([0x43,0xC1]), ie reading AVRMS i am getting [67,193] as output and for BVRMS [67,195] etc.
I tried the loop back test and is working fine.

I hope you will be able to advice me on this.
Thanks

HariKumar R

I didn't use this chip myself, but page 44 of
http://www.analog.com/media/en/technical-documentation/data-sheets/ADE7880.pdf
specifies that the values are 24-bit signed numbers, so you should be
reading three bytes. They say 0x39792C is the RMS value of full scale
input. You may be getting right data, and maybe you just need to scale it.

Hello Przemek,

Thank you for your immediate reply.

I am doubtful about the output because the voltage in B phase is Zero. Even then the reading is [67,195] and it is sequential compared to phase a data obtained ie [65,193]

Hope you can advice

this chip. Still, in general terms, I think you're doing the right thing:
provide it with known inputs and correlate the readout. For instance, if
you short out the input (zero out all voltages), what do you read?