by sjhntc on Thu Feb 06, 2014 6:20 pm

Hey everbody,

So I am in the process of trying to get my BeagleBone Black to communicate to my ADIS16488 IMU over SPI. I am using the Adafruit_BBIO.SPI libraries and to my knowledge all that I need to do is to write the high address, then write the low address and then read(1). When I do this I get no errors, which is good, but when I run my code it outputs all zeros. Is there something I am missing in my code? I've posted it below. Also here is a link to the data sheet:

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

Thanks for your time!
Sam

///////////////.py//////////////////////

from Adafruit_BBIO.SPI import SPI
import numpy as np

spi = SPI(0,1) #/dev/spidev1.1

spi.writebytes( [0x00] )
while(1):
....#XGYRO
....spi.writebytes( [ 0x12, 0x00,] ) # Register Low
....spi.writebytes( [ 0x10, 0x00 ] ) # Register High
....respx = spi.readbytes(1)

....#YGYRO
....spi.writebytes( [ 0x16, 0x00 ] ) # Register Low
....spi.writebytes( [ 0x14, 0x00 ] ) # Register High
....respy = spi.readbytes(1)

.... #ZGYRO
....spi.writebytes( [ 0x1A, 0x00] ) # Register Low
....spi.writebytes( [ 0x18, 0x00] ) # Register High
....respz = spi.readbytes(1)

....print '%10f %10f %10f\n' % (respx[0],respy[0],respz[0])
sjhntc
 
Posts: 6
Joined: Wed Jan 15, 2014 7:02 pm

by adafruit_support_mike on Fri Feb 07, 2014 12:41 am

I don't see a CS signal being sent LOW before you start the transmission. Do you have that?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 6960
Joined: Thu Feb 11, 2010 1:51 pm

by sjhntc on Fri Feb 07, 2014 2:13 am

I do not have a CS signal set low. This is my first time trying to configure SPI so I'm new to all of this. But I do see on the data sheet why it needs to be pulled low now. I'll give that a try and let you know if it works!

Thanks a bunch!
Sam
sjhntc
 
Posts: 6
Joined: Wed Jan 15, 2014 7:02 pm

by jwcooper on Fri Feb 07, 2014 11:20 am

If you're on Ubuntu or Debian, you need to take some extra steps to get SPI working. See in this thread for the details: http://forums.adafruit.com/viewtopic.php?f=49&t=48916

Most recent versions of Angstrom should be good to go though.

Note: I've also updated the installation instructions for Ubuntu: http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/installation-on-ubuntu
jwcooper
 
Posts: 45
Joined: Tue May 01, 2012 8:08 pm

by sjhntc on Fri Feb 07, 2014 4:08 pm

Mike,

I'm not seeing an address anywhere in the data sheet to call for the chip select. Did you see anything that indicated what the chips select address might be?

Thanks!
Sam
sjhntc
 
Posts: 6
Joined: Wed Jan 15, 2014 7:02 pm

by adafruit_support_mike on Fri Feb 07, 2014 11:41 pm

If you look at page 11 of the datasheet, you'll see a set of signal timing diagrams. Those show how the signals need to interact when you communicate with the chip.

In general, SPI is a shared-bus protocol that allows multiple devices to communicate using the same MOSI and MISO pins. To keep them from tripping over each other, each device has a CS (Chip Select) pin which tells that device whether it should pay attention to what's happening on MOSI/MISO or not. The general rule is that a device ignores all MOSI/MISO traffic unless its CS pin is held LOW.

Microcontrollers with hardware SPI have dedicated pins for MOSI, MISO, and CLK, but not for CS because you need a different CS pin for every device you want to control. Assigning that pin and toggling it to select the device is left to the circuit designer/programmer.

For your module, the CS signal should go to pin 6, between the RST and DOUT pins.. there's a diagram for that on page 10 of the datasheet, and according to that the module also generates interrupt signals on DOUT2. It would also be a good idea to connect the RST pin to VCC, but according to the datasheet you can leave it floating.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 6960
Joined: Thu Feb 11, 2010 1:51 pm

by sjhntc on Mon Feb 10, 2014 2:56 pm

Mike,

I've had the CS connected to the correct pin, and I understand what the chip select pin does. The problem I am having is setting that pin low in python. I'm a bit of a python newbie still and I've tried a few different things, but nothing has worked. So how would I notate setting the CS pin (pin 6) to low?

Thanks again!
Sam
sjhntc
 
Posts: 6
Joined: Wed Jan 15, 2014 7:02 pm

by sjhntc on Mon Feb 10, 2014 3:10 pm

Mike,

Also, here are two SPI_CS functions I found in the Adafruit IO library and I'm having a hard time interpreting what they mean...

/////////////////////////////////

SPI_get_cshigh(SPI *self, void *closure)
{
......PyObject *result;

......if (self->mode & SPI_CS_HIGH)
............result = Py_True;
......else
............result = Py_False;

......Py_INCREF(result);
......return result;
}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

SPI_set_cshigh(SPI *self, PyObject *val, void *closure)
{
......uint8_t tmp;

......if (val == NULL) {
......PyErr_SetString(PyExc_TypeError,
.................."Cannot delete attribute");
............return -1;
......}
......else if (!PyBool_Check(val)) {
............PyErr_SetString(PyExc_TypeError,
.................."The cshigh attribute must be boolean");
............return -1;
......}

......if (val == Py_True)
............tmp = self->mode | SPI_CS_HIGH;
......else
............tmp = self->mode & ~SPI_CS_HIGH;

......__SPI_set_mode(self->fd, tmp);

......self->mode = tmp;
......//printf("mode now: %x\n", self->mode);
......return 0;
}
sjhntc
 
Posts: 6
Joined: Wed Jan 15, 2014 7:02 pm

by adafruit_support_mike on Wed Feb 12, 2014 8:51 pm

That code is from the C source for the BBIO libraries, so it does a lot of things that are more important to the python interpreter than to the hardware.

The MAX31855 library does software SPI entirely in python: https://github.com/adafruit/PyBBIO/blob ... ax31855.py Take a look at that and see if it makes any more sense.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 6960
Joined: Thu Feb 11, 2010 1:51 pm