Atmega328p spi question

Hello,

I need help here, im using an atmega328p, the current design for my project has been working great.
I need to add can functionality and the connections for the spi slaves are confusing me.
I was going to run the Heltec 0.96' ssd1306 oled and the MCP2515 as SPI slaves.

The connections for the oled are confusing me. Could somebody please help me wire these 2 devices as spi slaves?

PLEASE NOTE the pin assignments in the code are the arduino pin numbers.

As per your schematic annotation, does this help:

CS# = SS#
SCK = SCK
SI = MOSI
SO = MISO

For the component marked OLED:

DATA = MOSI
CLK = SCK
CS = SS#

And you need a digital output pin to drive D/C.

Can I use the SPI oled and MCP2515 at the same time? Could you draw where I should connect the wires? thx

Yes. SPI is a serial bus. Each device is wired to the same MOSI, MISO and SCK signals. The only signal that isn't shared is SS. Each device has its own SS signal. The arduino pin that is connected to the device SS pin is usually specified when you call the .begin() function for the device.

Yes but here is no MISO pin being used on the oled?
Its only using MOSI and SCK. And the pin assignments in the code are different. The MOSI pin i thought should be pin 15 but its actually running on pin 13.
Pin 15 is assigned to D/C.

Looking at the screenshot of the code it looks like it's using a software implementation of SPI hardware.

This Adafruit article might help.

The SSD1306 datasheet doesn't indicate that a MISO signal is needed. This could be that the code never needs to read anything back from the display.

Yes that is correct, nothing needs to be read from the display.
Can SPI still be used if the LCD does not need a MISO. Just connect the MOSI, SCK and SS to the OLED and the MOSI, MISO, SCK and SS1 to the MCP2515?

Really appreciate your help with this.

Yes. :+1: SPI doesn't care if data is only being clocked out, or only clocked in.

Ok, I think I have it figured. Any chance you could have a look at my schematic and see if I have missed anything?
Read something about pullup resistors etc.
PM me if you like because I am happy to financially compensate you for your time and help.

Your SPI connections look ok. I assume that your OLED pins are correct.

Regarding pullup resistors, I don't think that they are needed for an SPI bus, but somebody more knowledgeable may be able to confirm this. They are required when using an I2C bus, which is where you may have come across the term.

What about for the programming port, having the MCP2515 connected won’t interfere when I’m flashing the 328p.

If you put pull up resistors on your CS1 & CS2 signals, then that will ensure that the SPI devices don't accidentally get selected when programming the 328p. During programming the 328p is held in reset (i think!) which means that your CS pins float. The resistors take care of that.

I don't see bypass caps. You've got 4 chip connections to Vcc; you should have a 0.1uF cap for each one (positioned near their respective chips.)