SPI Communication

18 Dec 2010

I am trying to interface this gyroscope module: http://www.active-robots.com/products/parallax/datasheets/sensory/27922-LISY300GyroscopeModuleV1.0.pdf to the SPI pins on mBed.

According to the datasheet, communication is done via SPI. Naturally, I can connect mBed's SCLK to the gyroscope's SCLK and mBed's MISO to the gyroscope's SDATA., serial data output However, the gyroscope module doesn't have a MOSI interface pin to write to for a response. What should I do then? I have a way around this using an oscillator and an interrupt to read the serial output but I'd rather use the SPI interface on mBed since it'll be a less tedious.

18 Dec 2010

The basic SPI action is to read data in via MISO during the same 16 SCK clock cycles as data is sent out via MOSI

You do not send data to the module so you do not need a physical MOSI connection, but you do need to send dummy data out in order to read the wanted data in.

18 Dec 2010

So, you're saying data can be read from the MISO pin directly? Like, if p6==1, etc etc?

18 Dec 2010

Yes you can read from MISO pin but that's not what is meant here.

If you connect the serial data out from an SPI slave device to MISO and the clk signal then sending any data out of the unconnected MOSI will clock data into MISO. This your slave device is simply "read only" as you haven't connected MOSI.

So doing int i = spi.write(0x00); is the same as int i = spi.write(0xFF); or any other value you write. The value writen is simply "don't care". You're not actually writing anything. What you are doing is making the SPI clock signal actually clock, thus clocking data out of the slave and into MISO.

18 Dec 2010 . Edited: 18 Dec 2010

I see what you mean.

Also, without connecting the mBed to anything but the power supply, I tried looking at the SCLK pin with an oscilloscope but all I get is floor noise. I assumed that SCLK will only clock when the spi.write command is issued. But I set the mode to 3 which means the base value of the clock should be high (larger than 2V). It was just a test so what I did is shown below. Do you think there might be problems with the pin, or, I can't test the SCLK output by using just those pins?

int main() {
    spi.format(15,3);
    spi.frequency(1000000);
}
18 Dec 2010

Use a program like this to test. Don't just give us snippets, your above code does nothing.

Connect p5 to p6 (MOSI to MISO) and then try this:-

#include "mbed.h"

SPI spi(p5, p6, p7); // mosi, miso, sclk

Serial pc(USBTX, USBRX); // tx, rx

int main() {
    spi.format(8,3);
    spi.frequency(1000000);

    while (1) {
        for (int i = 0; i < 10; i++) {
            int j = spi.write(i);
            pc.printf("%d ", j);
        }
        pc.printf("\r\n");
        wait(1);
    }
}

Note that because you connect p5 to p6 any value you write will loopback to the input.

18 Dec 2010

Alright, gotcha. I'll try it out. Thanks.

09 May 2016

hello, I have component adc LTC1400, i would to progam this adc in SPI because i don't know. Can you help me please.

16 May 2016

It looks a bit odd but looks like it might be SPI mode 0 or 1, 15 bit!!

You could try useing MOSI to send the "conv" pulse. Send a word 0x4000 to generate one trigger pulse. MOSI to conv MISO to Dout CLK to CLK