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

Thread: SPI - shared pins problem

  1. #1

    SPI - shared pins problem

    Hello, I'm working on a synth using a T3.6 and the audio board. It works great and sounds fantastic (I might show it off soon). I've added an SPI display (one of these) and I tried connecting it, sharing pins SCLK 14 and MOSI 7 with the audio board. It doesn't work, the display won't update, the SD card reader fails and there's a horrible noise from the headphone socket. If I change them to SCLK 20 and MOSI 21, everything works fine.

    I would like to know why using the shared pins doesn't work in this case, thanks. The pins I'm using are shown below:

    //Audio Board
    #define SDCARD_CS_PIN 10
    #define SDCARD_MOSI_PIN 7
    #define SDCARD_SCK_PIN 14

    //ST7735 SPI display
    #define sclk 20 // SCLK can also use pin 14 - DOESN'T WORK
    #define mosi 21 // MOSI can also use pin 7 - DOESN'T WORK
    #define cs 2 // CS & DC can use pins 2, 6, 9, 10, 15, 20, 21, 22, 23
    #define dc 6 // but certain pairs must NOT be used: 2+10, 6+9, 20+23, 21+22
    #define rst 8 // RST can use any pin

    Audio Board overlayed with Teensy 3.6

    Click image for larger version. 

Name:	Capture.jpg 
Views:	32 
Size:	78.9 KB 
ID:	16714

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Cold hollow VT
    I notice that MOSI 21 is on #1 while MOSI 7 is on #0. Same for SCLK. They are on a different SPI bus.

  3. #3
    Which is why it works. They should work on the same bus, I thought.

  4. #4
    Senior Member
    Join Date
    Nov 2015
    Cold hollow VT
    Your #DEFINES are for bus 0. There are 3 different SPI buses on T3.5 and T3.6. Each of those buses requires a different driver, unless you use the one @KurtE has created.

    Bus #0 uses MISO pin 12, MOSI pin 11, SCLK pin 13. They have alternates available on miso-8, mosi-7, sclk-14.

    The alternate pin for MOSI#1 on 21would be pin 0. Alternate for SCK#1 on pin 20 would be pin 32. Likewise MISO#1 on pin 5 would be pin 1.

    Which bus are you trying to use?

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Again always hard to answer questions like this without enough details, like seeing the code. Could be hardware incompatibility or software bug or...

    Example: I don't remember if some of the ST7735 boards have issues with some of their pins holding the state or not...

    Also don't know if for example the Audio library uses pin 6? By the product page, it might to access the optional memory chip?
    Audio	9, 11, 13, 18, 19, 22, 23	18, 19 (other I2C chips)
    Volume Pot	15 (A1)	-
    SD Card	7, 10, 12, 14	7, 12, 14 (other SPI chips)
    Memory Chip	6, 7, 12, 14	7, 12, 14 (other SPI chips)
    Again looks like on the Audio page, that pin 10 is SD cards chip select and pin 6 is the memory chip select so I would avoid those.

    Also software wise, I don't know what library you are using for your display. Does it for example have code the enables the CS pin only when needed.

    Also many times with shared SPI pins with multiple devices, the hardware wiring and/or software init code needs special attention. That is if one of the libraries starts up it's init code and tries to initialize the device, but some other chip select pin is either floating or in wrong state, that other device might steal or interfere with the init code and as such the device does not work properly, often neither work properly.

    This can often be fixed by either:

    a) Hardware - Use external Pull up resistors on the CS pins, such that when the hardware is initialized it will not be floating...
    b) Software - Before calling any of the init functions for your SPI devices. Do something like:
    pinMode(cs, OUTPUT);
    digitalWrite(cs, HIGH);
    Call audio init
    call display init...

  6. #6
    Hello, thanks for the answers. I'm trying to attach the display to the same bus as used by the audio board - bus 0.

    I don't remember if some of the ST7735 boards have issues with some of their pins holding the state or not...
    That sounds like a possible explanation. I'll have a go with suggestion b). As I stated though, everything works with the display on bus 1, I just wanted to save a couple of pins.

  7. #7
    Senior Member
    Join Date
    Nov 2015
    Cold hollow VT
    @KurtE The OP was mentioning pins related to different SPI busses. Not knowing what his intentions were I chose to relay to him your SPI driver that handled multiple SPI busses.

    @UHF I have not used the audio shield BUT I think (check it) the audio shield uses I2S (?) on pin #13 that conflicts with the SPI0 sclk so you would have to use the alternate SCK0 pin on #14 or #27 for SPI0 to function.

Posting Permissions

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