As of April 2, 2014, this has been fixed using DMA SPI. See reply #15 for working copy of the code.
DMA SPI obtained from
DUEZoo/dmaspi.ino at master · manitou48/DUEZoo · GitHub
Hi guys,
I'm trying to program a ship that requires 4 wire serial programming (essentially SPI)
For those who are curious, it's the LM96570.
The chip uses up to 80MHz on the serial line.
I've been able to create a simple program for my Due to communicate with the chip.
The issue I'm having is that although the SPICONTINUE works as it is intended to (by leaving the LE low), the data is transmitted in little "burts" of information, one byte (8 bits) at a time, then a long delay before the next byte.
The clock flips as I expect it to, but again, flips 8 times and then there is a long pause.
I am suspecting that it's causing mis-communication problems with my IC chip, and the lowest I've been able to achieve a constant clock is down at 800KHz. I was wondering if any of you had any luck pushing continuous SPI communication to tens of MHz without these long pauses between bytes.
Any suggestions to make my code more efficient is also welcomed.
I am passing the bytes from a python serial script.
#include <SPI.h>
// Define SPI Pins
// Can only use 4 10 and 52
#define LEPin 10
// Save Words to write to API
// Integer is 4 byte in Due (32 bits)
// Worst Case scenario is need to write 70 bits (5 addr + 0 + 64 data)
unsigned char Word1 = 0xAA;
unsigned char Word2 = 0xFF;
unsigned char Word3 = 0x00;
unsigned char Word4 = 0x00;
unsigned char Word5 = 0x00;
unsigned char Word6 = 0x00;
unsigned char Word7 = 0x00;
unsigned char Word8 = 0x00;
unsigned char Word9 = 0x00;
void setup()
{
// Set up Serial communication (Computer)
Serial.begin(115200);
Serial.println("Initialisation Started");
// Set up SPI communication (Chip)
SPI.begin(LEPin);
SPI.setClockDivider(LEPin, 42); // Desired 80 MHz Due is 84, so try div 2
// 84 should correspond to 1MHz
SPI.setBitOrder(LEPin, MSBFIRST);
// TODO: SPI Set Data Mode http://arduino.cc/en/Reference/SPISetDataMode
SPI.setDataMode(LEPin, 0);
Serial.println("Initialisation Completed");
}
void loop() {
if (Serial.available()) {
serialRead();
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialRead() {
Serial.println(" "); // Unknown why it's required
//Serial.print("READ");
Word1 = Serial.read();
Word2 = Serial.read();
Word3 = Serial.read();
Word4 = Serial.read();
Word5 = Serial.read();
Word6 = Serial.read();
Word7 = Serial.read();
Word8 = Serial.read();
Word9 = Serial.read();
//Serial.print("READSUCESS");
SPI.transfer(LEPin, Word1, SPI_CONTINUE);
SPI.transfer(LEPin, Word2, SPI_CONTINUE);
SPI.transfer(LEPin, Word3, SPI_CONTINUE);
SPI.transfer(LEPin, Word4, SPI_CONTINUE);
SPI.transfer(LEPin, Word5, SPI_CONTINUE);
SPI.transfer(LEPin, Word6, SPI_CONTINUE);
SPI.transfer(LEPin, Word7, SPI_CONTINUE);
SPI.transfer(LEPin, Word8, SPI_CONTINUE);
SPI.transfer(LEPin, Word9, SPI_LAST);
// Return 1 so computer knows that Arduino is ready to receive next command
delay(1000);
Serial.print("1");
//Serial.print("DONE");
}