Interfacing L6470 stepper driver via SPI
Topic last updated
19 Sep 2012, by
Philip Schmidt.
7 replies
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
Replies
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:
Library for ST's new dSpin stepper motor driver. Works with their demo board L6470EVAL.
. I would try if it works with that first.
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:
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.
Then it seems like a reasonable assumption to me that the code is not the issue, but something with the hardware connection is.
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.
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
Checked! Sadly, there was no fault. I've red before thats communicating with this chip is a little bit difficult, but so hard?
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!
Please log in to post a reply.
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