[Teensy 4.1] SPI1 not working....

Hello all,

I am using Teensy 4.1 (using Platform IO with up-to-date Teensy 4.1 library) to drive an external ADC using SPI1 (LSPI3?!).
Unfortunately, SPI1 is not working. Checking the signals with logic analyzer nothing is happening, since SCK is not working.

I am initializing SPI1 in setup() and testing it in loop() as below:

Code:
void setup(){
 ...
 Serial.begin(...);

 SPI1.begin();
 SPI1.setMOSI(26);
 SPI1.setSCK(27);
 SPI1.setMISO(1);
 SPI1.setCS(0);
 ...
}

void loop(){
 ...
 delay(100);
 SPI1.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0));
 SPI1.transfer(0x42);
 SPI1.endTransaction(); 
 ...
}

Using "bit-banging" is working, so the cable connections should be fine. Do I missing something here ?!

Thank you !

Best regards,

opcode_x64
 
Last edited:
First guess: SPI1.setCS(0);

May not do what you are expecting it to do. It is only setting up the CS pin to work as a hardware CS pin, i.e setting the IOMUX setting on that pin, and returning to you the mask.
Then to use it, you need to set the right register(TCR)... Normally only lower level code like some of display libraries work this way...

Although it is possible that might work...
Note: you dont need most of your set functions as they are the default pins...
That is you should be able to say:

SPI1.begin()
pinMode(0, OUTPUT);

...
Code:
void loop(){
 ...
 delay(100);
  digitalWriteFast(0, HIGH);
 SPI1.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0));
 SPI1.transfer(0x42);
 SPI1.endTransaction(); 
  digitalWriteFast(0, LOW);
 ...
}

Sometimes I have run into other code that overwrites the settings:
Like someone doing: pinMode(1, OUTPUT);
Or Serial1.begin()...
 
Back
Top