Using SPI with multiple systems at same time

Hello everyone,
I have two OLED screens running off the Adafruit_SSD1306 Library [ GitHub - adafruit/Adafruit_SSD1306: Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs ] and a 8x8 LED Matrix running off a MAX7219 (not using a library).

The Adafruit library runs Wire.begin() via it's last parameter

Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset, bool periphBegin) {

I am manually calling it when begin my Matrix.

void Matrix::begin(byte pin) {
  _pin = pin;
  pinMode(_pin, OUTPUT);
  SPI.begin();
  write(0x0F, 0x01); // Run test - All LED segments lit.
  delay(1000);
  write(0x0F, 0x00); // Finish test mode.
  write(0x09, 0x00); // Disable BCD mode. 
  write(0x0a, 0x0F); // Use hightest intensity. 
  write(0x0b, 0x0f); // Scan all digits.
  write(0x0C, 0x01); // Turn on chip.
  clear();
  _debug.write("Matrix Setup : Pin #").line(_pin);
}

void Matrix::write(uint8_t address, uint8_t value) { 
  digitalWrite(_pin, LOW);
  SPI.setBitOrder(MSBFIRST);   // Reverse the SPI Data o/p. 
  SPI.transfer(address);   // Send address.
  SPI.transfer(value);     // Send the value.
  SPI.setBitOrder(LSBFIRST);   // Reverse the SPI Data o/p. 
  digitalWrite(_pin, HIGH); // Finish transfer.
}

Do I have to worry about having SPI.begin() gettting called twice? At first I thought I should initialize/begin once inside the class I have that controls the entire project. However, since that is not in the global memory will it not effect the other instances of SPI? Do I need to create an member variable instance and pass the reference to any other usages of it? Not sure how I can do that when using the Adafruit_SSD1306 library. Maybe I have to begin it in the global space (Main.ino)?

Sorry for the scattered questions...I'm just not sure how to handle it.

If it matters...the OLEDs work perfectly when just letting the code begin() multiple times. However the LED Matrix displays the info for about 3-5 seconds and then it disappears (I can't find a way to make it stay). I'm not sure if the begin() issue is causing this of course but I figured I would learn/explore how it works.

Thanks for your time.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.