0

How to Use Multiple SPI Devices with OLED DIsplay Arduino
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How to Use Multiple SPI Devices with OLED DIsplay Arduino

by epalaima on Sun Jun 11, 2017 1:51 pm

Hi I am working with one of your 128x64 Monochrome OLED displays. In the tutorial given here: https://learn.adafruit.com/monochrome-oled-breakouts/wiring-1-dot-3-128x64 it says that the pins can also be used for other SPI devices. When I add SPI.begin() to my setup function the display stops working.

Is this because SPI is setup internally with a custom configuration by the display.begin() function, and will this allow me to use SPI Library functions like SPI.transfer or do I have to do additional setup?

epalaima
 
Posts: 81
Joined: Sat Jan 23, 2016 6:48 pm

Re: How to Use Multiple SPI Devices with OLED DIsplay Arduin

by adafruit_support_bill on Sun Jun 11, 2017 2:26 pm

You can share the MOSI, MISO and SCK pins on the SPI bus. But each SPI device requires a unique CS (Chip Select) pin. Only one device can be selected for communication at a time. Typically this must be specified in your code when declaring the device.

adafruit_support_bill
 
Posts: 62261
Joined: Sat Feb 07, 2009 10:11 am

Re: How to Use Multiple SPI Devices with OLED DIsplay Arduin

by epalaima on Sun Jun 11, 2017 8:18 pm

I manually pull down the CS pin in my transfer function for writing to a SPI DAC. Is there something I need to do to insure that the CS for the OLED will be high during this transfer?

epalaima
 
Posts: 81
Joined: Sat Jan 23, 2016 6:48 pm

Re: How to Use Multiple SPI Devices with OLED DIsplay Arduin

by adafruit_support_bill on Mon Jun 12, 2017 5:59 am

CS is asserted by pulling it LOW. The OLED library (and most other libraries for SPI devices) will do this for you. You just need to specify to the library which pin to use for CS.

adafruit_support_bill
 
Posts: 62261
Joined: Sat Feb 07, 2009 10:11 am

Re: How to Use Multiple SPI Devices with OLED DIsplay Arduin

by epalaima on Tue Jun 13, 2017 3:09 am

Sorry I think I communicated what I meant poorly. I know SPI CS is asserted by pulling the pin LOW. What I meant was if the CS for the OLED was automatically controlled by the display library.

I think the problem was that I was trying to use the SPI DAC as part of an interrupt. Could this cause problems if the interrupt is called in the middle of an OLED SPI transfer. It seems like the OLED is getting bad SPI data somehow, otherwise I don't see why it would stop working as soon as I tried to add the DAC.

epalaima
 
Posts: 81
Joined: Sat Jan 23, 2016 6:48 pm

Re: How to Use Multiple SPI Devices with OLED DIsplay Arduin

by adafruit_support_bill on Tue Jun 13, 2017 6:15 am

The display library does control the CS. But if you are trying to do SPI transfers to the DAC in an interrupt, you could be disrupting communications with the display.

The SSD1306 library does support 'software i2c'. You can specify any 4 pins in the constructor for your SPI bus. Choosing different pins would avoid any conflict with the DAC.
Code: Select all | TOGGLE FULL SIZE
  Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);

adafruit_support_bill
 
Posts: 62261
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.