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

Thread: SPI hanging on trivial code

  1. #1

    SPI hanging on trivial code

    I can't see what I'm doing wrong here, I get the feeling I'm missing something obvious.

    Teensy4.1, Arduino IDE 2.0.4

    Code:
    #include <SPI.h>
    
    int count;
    
    void setup() {
      delay(1000);
      count = 0;
    }
    
    void loop() {
     Serial.printf("Loop %d\r\n",++count);
     SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
     if (count == 10)
       SPI.transfer(0xff);
     SPI.endTransaction();
     delay(1000);
    }
    Gives the result

    Code:
    Loop 1
    Loop 2
    Loop 3
    Loop 4
    Loop 5
    Loop 6
    Loop 7
    Loop 8
    Loop 9
    Loop 10
    and then locks up. No matter what I do the system dies as soon as I call SPI.transfer()

    SPI1 and SPI2 show exactly the same results as SPI.

    Please tell me what stupid mistake I'm making because everything I can find says this should work.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,656
    Add SPI.begin() in your setup() function.

  3. #3
    Thank you.
    Now excuse me while I go and kick myself a few more times...

Posting Permissions

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