Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: [Teensy 4.1] SPI1 not working....

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    11

    [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 by opcode_x64; 11-13-2021 at 09:41 PM. Reason: changed title...

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,722
    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()...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •