Hello.
I'm using Teensy as an SPI master for a project I am working on, but I am having some trouble getting reliable data transmission working. I am seeing the transmitted byte corrupted approximately 50% of the time. I have run the below test on my Teensy LC and a 3.6 and I see the same on both.
I have connected the Teensy to a logic analyzer to see what's coming down the wires. On the occasions that the transmit fails, I can see some ripples on the slave select, SPI clock and MOSI signals where there ought not to be.
Here are some captures from my FPGA based logic analyzer where I am sending the number 9 as the byte (00001001). The first image is a successful data transmission, the other two are bad ones. Note that ssel = SS in the images.
Correct:
Incorrect:
My Arduino Code and Setup
The Teensy is on a piece of breadboard, powered by USB.
My pins are setup as:
SS: 10
SCK: 13
MOSI: 11
MISO: 12
The pins are connected to the FPGA logic analyzer by < 10cm solidcore hookup wire.
Here is my teensy sketch, which sends a number that you type in the serial monitor every second:
Other Notes
I've tried this with various different SPI clock speeds and I generally see the same behavior.
Because I've seen this on two different Teensys models, I suspect it must be something I have done wrong, but I cannot see atypical with my spi setup or test code.
Any help or advice appreciated.
Thanks.
I'm using Teensy as an SPI master for a project I am working on, but I am having some trouble getting reliable data transmission working. I am seeing the transmitted byte corrupted approximately 50% of the time. I have run the below test on my Teensy LC and a 3.6 and I see the same on both.
I have connected the Teensy to a logic analyzer to see what's coming down the wires. On the occasions that the transmit fails, I can see some ripples on the slave select, SPI clock and MOSI signals where there ought not to be.
Here are some captures from my FPGA based logic analyzer where I am sending the number 9 as the byte (00001001). The first image is a successful data transmission, the other two are bad ones. Note that ssel = SS in the images.
Correct:
Incorrect:
My Arduino Code and Setup
The Teensy is on a piece of breadboard, powered by USB.
My pins are setup as:
SS: 10
SCK: 13
MOSI: 11
MISO: 12
The pins are connected to the FPGA logic analyzer by < 10cm solidcore hookup wire.
Here is my teensy sketch, which sends a number that you type in the serial monitor every second:
Code:
#include <SPI.h>
const int slavePin = 10;
SPISettings spiSettings(5000000, MSBFIRST, SPI_MODE0);
void setup() {
digitalWrite(slavePin, HIGH);
pinMode (slavePin, OUTPUT);
SPI.begin();
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) // is a character available?
{
char serial_byte = Serial.read();
// check if a number was received
if ((serial_byte >= '0') && (serial_byte <= '9'))
{
Serial.print("Number received: ");
Serial.println(serial_byte);
byte num = serial_byte - '0';
while(true)
{
SPI.beginTransaction(spiSettings);
digitalWrite(slavePin, LOW);
SPI.transfer(num);
digitalWrite(slavePin, HIGH);
SPI.endTransaction();
delay(1000);
}
}
}
}
Other Notes
I've tried this with various different SPI clock speeds and I generally see the same behavior.
Because I've seen this on two different Teensys models, I suspect it must be something I have done wrong, but I cannot see atypical with my spi setup or test code.
Any help or advice appreciated.
Thanks.