Interfacing L6470 stepper driver via SPI

16 Sep 2012

Hi,

I try to interface a L6470 stepper driver (dSPIN) from SparkFun via the mbed SPI with the following code:

#include "mbed.h"

DigitalOut myled(LED1);
DigitalOut myled2(LED2);
Serial usb(USBTX, USBRX);
DigitalOut standby(p18);    //standby/reset pin
DigitalOut cs(p8);          //chip select pin

DigitalIn flag(p19);
DigitalIn busy(p20);
SPI _spi(p11, p12, p13);

int main() 
{
    myled = 1;
    standby = 1;
    cs = 1;
    standby = 0;
    wait(1);
    standby = 1;
    wait(1);
    _spi.frequency(1000000);
    _spi.format(8,3);
    wait(1);
    myled = 0;
    while(1)
    {
        wait(2);
        myled = 1;
        cs = 0;
        _spi.write(208);
        cs = 1;
        wait_us(1);
        cs = 0;
        int stat1 = _spi.write(0);
        cs = 1;
        wait_us(1);
        cs = 0;
        int stat2 = _spi.write(0);
        cs = 1;
        int statBusy = busy.read();
        usb.printf("Busy: %i ",statBusy);
        int statFlag = flag.read();
        usb.printf("Flag: %i ", statFlag);
        usb.printf("Status Byte 1: %i ", stat1);
        usb.printf("Status Byte 2: %i ", stat2);
        myled = 0;
        wait(2); 
        myled2 = 1;
        cs = 0;
        _spi.write(54);
        cs = 1;
        wait_us(1);
        cs = 0;
        int stepMode = _spi.write(0);
        cs = 1;
        wait_us(1);
        usb.printf("Step Mode: %i\n", stepMode);
        myled2 = 0;
    }
}

Sadly I got only zero's from the dSPIN - and I realy don't know why cause I can't find any mistake in my code.

I hope someone could help me.

Best regards

16 Sep 2012

Do you power the board with 3.3V or 5V? Not sure if it matters, but 3.3V should at least work.

Anyway there is already an mbed library for this device:

Import librarydSPIN

Library for ST's new dSpin stepper motor driver. Works with their demo board L6470EVAL.

. I would try if it works with that first.

16 Sep 2012

Erik - wrote:

Do you power the board with 3.3V or 5V? Not sure if it matters, but 3.3V should at least work.

Anyway there is already an mbed library for this device:

Import librarydSPIN

Library for ST's new dSpin stepper motor driver. Works with their demo board L6470EVAL.

. I would try if it works with that first.

I've tried both, 3.3V and 5V. I've also tried the lib but everytime I send a command the error flag rises. Except the 'get_status' but it returns also zero.

16 Sep 2012

Then it seems like a reasonable assumption to me that the code is not the issue, but something with the hardware connection is.

17 Sep 2012

I rewired it and retried my code and the lib. My code still throws zeros, with the lib I get '65535' from the 'get_status' funktion, wich can't be right. I realy don't understand this.

18 Sep 2012

I'm not trying to offend you but sometimes people misinterprete the meaning of MOSI and MISO with something like Serial In (MOSI) and Serial Out (MISO). So they connect MOSI to SDO and MISO to SDI. But that's not correct. MOSI actually means "Master Out Slave In" and should be connected to SDI (LPC1768 is the master) and correspondingly MISO (Master In Slave Out) to SDO.

Probably that's not your problem but it's still worth checking.

Best regards
Neni

18 Sep 2012

Checked! Sadly, there was no fault. I've red before thats communicating with this chip is a little bit difficult, but so hard?

19 Sep 2012

OK, found my very very silly error: everytime I tried to communicate with the dSPIN I hadn't connect the main power to it, cause I thought that the logic should work only with the 5V input. Now I've got a new connector and tried it - and it's working :) Anyway, very much thanks for your help!

18 Dec 2016

Nenad Milosevic wrote:

I'm not trying to offend you but sometimes people misinterprete the meaning of MOSI and MISO with something like Serial In (MOSI) and Serial Out (MISO). So they connect MOSI to SDO and MISO to SDI. But that's not correct. MOSI actually means "Master Out Slave In" and should be connected to SDI (LPC1768 is the master) and correspondingly MISO (Master In Slave Out) to SDO.

Probably that's not your problem but it's still worth checking.

Best regards
Neni

LOL! Not offended in the LEAST! I was having issues communicating with my L6472 board (own design, dual L6472 and MCU to control them) and had checked just about everything, from the pin outs of the package in Eagle, ohmed everything out, verified power,enable,etc. and STILL couldn't get anything to work. It always set the error flag as soon as I tried to talk to either driver.

When I saw your post, I went back and looked over the schematic one more time. Sure enough, I CLEARLY had MOSI -> MISO!!! And the whole point of "MOSI" vs. "TXD" or "MISO" vs. "RXD" was so you didn't have to remember to swap TXD to RXD! And I did it anyway!

Thanks for the mental jab! A quick patch on the PCB and everything is talking and working as expected.