BBB//ADXL375Z//BBIO.SPI

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
stuart.reynard
 
Posts: 5
Joined: Fri Mar 28, 2014 9:01 pm

BBB//ADXL375Z//BBIO.SPI

Post by stuart.reynard »

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

Per the data sheet (link below), 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.

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'm happy to come back with any additional info.

Thanks,
Stuart

Datasheet for ADXL375:

http://www.analog.com/static/imported-f ... DXL375.PDF

User guide for the breakout board for my accelerometer (ADXL375Z) in case it is helpful:

http://www.analog.com/static/imported-f ... _Guide.pdf

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BBB//ADXL375Z//BBIO.SPI

Post by adafruit_support_mike »

Post your complete code (or a complete 'test the SPI' script) and we'll see what we can do.

One thing to check: are you pulling the CS pin low before trying to send the commands/data? That's one of the key differences between I2C and SPI.. I2C devices respond based on an address match, SPI devices respond based on the state of their CS pin.

User avatar
stuart.reynard
 
Posts: 5
Joined: Fri Mar 28, 2014 9:01 pm

Re: BBB//ADXL375Z//BBIO.SPI

Post by stuart.reynard »

Thanks for getting back to me, Mike.

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-be ... 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(
  • )
    spi.readbytes(numBytes)

    OR if I can just do

    spi.writebytes(
    • )
      spi.readbytes(numBytes)

      I admittedly have not written a 'test the SPI' script. The code that I wrote in my original post is basically all that I have written.

User avatar
stuart.reynard
 
Posts: 5
Joined: Fri Mar 28, 2014 9:01 pm

Re: BBB//ADXL375Z//BBIO.SPI

Post by stuart.reynard »

Just to be clear, I have actually tried using the code from my original post, but I receive [0] back from readbytes() when I would expect to get the DEVID of the accelerometer.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: BBB//ADXL375Z//BBIO.SPI

Post by adafruit_support_mike »

You may need to enable a device tree overlay to get SPI working. The BBB's GPIO is kind of tricky that way.

The BBIO installation process from the tutorial should set everything up: http://learn.adafruit.com/setting-up-io ... k/overview Give that a try and see if you can get any response from the device.

User avatar
stuart.reynard
 
Posts: 5
Joined: Fri Mar 28, 2014 9:01 pm

Re: BBB//ADXL375Z//BBIO.SPI

Post by stuart.reynard »

Yeah, I was concerned that it was an overlay issue. I assumed the BBIO library would export the overlays as part of its setup process.

I will try the setup process again...

User avatar
stuart.reynard
 
Posts: 5
Joined: Fri Mar 28, 2014 9:01 pm

Re: BBB//ADXL375Z//BBIO.SPI

Post by stuart.reynard »

For the sake of closure, I ended up using a different driver file. I documented my process on the following Google Group thread:

https://groups.google.com/forum/#!categ ... oJFqmXraCw

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”