I am working with the Teensy4.0 and compiling in both Arduino IDE and using Visual Studio with Visual Micro plugin (shame the debug does not work!!!)
Arduino 1.8.13 and TeensyDuino 1.53
Anyway using SPIClass to communicate on SPI channel0 to a DAC8775 development board. The SPI links are very short. The CS Pin is Pin 15
I think there is an issue with the SPI Library for Teensy and the SPI.BeginTransaction(SPISettings(spi_speed, bit_order, mode)) is not setting the SPI clock speed correctly.
This was found as using the Teensy4 at 150MHz and has a few issues. From using the Logic logic analyzer on the SPI and fixed a few timing issues by placing a delayMicroseconds(2) after setting CSPin LOW and then after SPI.Transfer(data) another delay delayMicroseconds(2) before setting the CSPin HIGH again. The code for writing (of course there is a method for readings):
void DAC8775Control:
AC8775SPIWrite(byte registryAdr, uint16_t data)
{
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE1));
#if DEEP_DEBUG_LEVEL_TWO
digitalWrite(_csPin, LOW); //Mark for Logic Analyzer for testing and speed of switching, not needed for normal use
digitalWrite(_csPin, HIGH);
delayMicroseconds(2);
#endif
digitalWrite(_csPin, LOW);
delayMicroseconds(2); //This delay is absolutely needed to ensure timings
SPI.transfer(registryAdr);
SPI.transfer16(data); //Data is always 16bit for the DAC8775
delayMicroseconds(2); //This delay is absolutely needed to ensure timings
digitalWrite(_csPin, HIGH);
SPI.endTransaction();
}
I can get this to work for 150MHz and confirm this by writing to a registry (UserBit) on the DAC8775 and then reading it back to confirm an SPI Comms check.
However, if I now crank up the Teensy speed up to above 150MHz it falls over. Does NOT work for 450MHz or 600MHz regardless of what speed I put in the SPISettings.
Played around for a long time (36 hours) with timings and delays and SPISettings. It always fails above 150Mhz.
So I then used the following:
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE1));
SPI.setClockDivider(SPI_CLOCK_DIV64);
And I get it to consistently pass at 600Mhz, also works with SPI_CLOCK_DIV32. But fails at 600Mhz with SPI_CLOCK_DIV16 (not unexpected).
So in conclusion, I think that the SPI library and in particular the SPISettings is not setting the correct SPI clock speed.
atb Jim