SPI.transfer hangs in Teensy 4.0 but works good in Teensy 3.2

Status
Not open for further replies.

chensx2012

Active member
Recently I moved my old code from Teensy 3.2 to 4.0, and found out that the same code works perfectly in T3.2, but hangs in T4.0.
Code:
void send_cmd(uint8_t cmd)
{
	SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE1));
	digitalWriteFast(PIN_ADS_CS, LOW);
	delayMicroseconds(10);
	SPI.transfer(cmd);
	delayMicroseconds(10);
	digitalWriteFast(PIN_ADS_CS, HIGH);
	SPI.endTransaction();
}
Later I confirmed that the code stuck in SPI.transfer(cmd) for Teensy 4.0. Is this a bug?
 
Hard to say if it is a bug or not? As I don't see the rest of the program that is calling this. For example is SPI.begin() called?
If not maybe the SPI subsystem is not enabled and causes it to fault.

What is the hardware hooked up to it? Hopefully something that is not doing +5v as the T4 is not 5v tolerant where as the T3.2 is.
 
Later I confirmed that the code stuck in SPI.transfer(cmd) for Teensy 4.0. Is this a bug?

Very strange. SPI has no error checking or "delays". I often do SPI performance tests with no wires connected to anything! So I don't understand how a sketch can hang in a SPI.transfer(). As KurtE notes, you need to provide full sketch.
 
Status
Not open for further replies.
Back
Top