Sharing MISO, MOSI, etc (SPI pins)

At the moment I’m using an SSD1331, which uses the following pins:

#define sd_cs   A2
#define sclk    A3
#define miso    A4
#define mosi    A5
#define cs      A6
#define rst     D2
#define dc      D5

This is working perfectly fine at the moment.

My question is whether or not I can share or re-use pins for this BLE Breakout Module, which also requires the SPI pins:

Fritz file:

Thanks in advance for your help.

Yes you can as long as the SPI settings don’t conflict (e.g. have a common speed, byte order, …).

If you can find such a setting you only have to ensure that each device has its own CS/SS line and there is only one of these active at any given time.
If you can’t find such a setting, you’d have to use SoftSPI on different pins.

@ScruffR, just a slight clarification. The SPI speed needs to be set to the slowest of all the SPI slaves. As @BDub had discovered, you can actually set SPI speed and byte order “on the fly” without “glitching” the bus but at the cost of the time it takes to do the settings. The biggest problem is when the SPI slaves use different bus modes. This is where using SoftSPI on one device and hardware SPI on others is a good idea.

On thing to remember with BLE is that its radio will interfere with the Core’s radio since they are on the same band. Consideration will need to be taken for that. :smile:

2 Likes

Thanks for your help @peekay123 and @ScruffR. It's very much appreciated.

I have a couple of questions:

[quote="peekay123, post:3, topic:9331, full:true"]
The SPI speed needs to be set to the slowest of all the SPI slaves.[/quote]

Do you mean that I would need to use the following methods to set this?

For example:

SPI.setClockDivider(pin_mosi, SPI_CLOCK_DIV2); or do I only need to pass the SPI_CLOCK_DIV2 and it will set it to all of the SPI pins?

I read that both Wi-Fi and Bluetooth fail gracefully in the presence of interference. And that this means that the communication protocols are very robust and include mechanisms for error checking and correcting, as well as requesting that corrupted packets be resent. Therefore the result of increasing levels of interference is almost always confined to a slowing of the data rate as more packets need to be resent. Only in extreme conditions, such as setting a Bluetooth enabled cell phone down next to an operating microwave oven, is it likely that communications will cease altogether.

It also went on to explain that when a Bluetooth device encounters interference on a channel, it deals with the problem by hopping to the next channel and trying again. In this manner it can attempt to avoid interference from a Wi-Fi network.

Does this apply to breakout modules sitting on a breadboard or PCB? I would still consider myself a newbie to electronics and I try to gather as much information as I can so as to make sure I'm doing the right things, but the more I read into this the more it seems like there's a few things I'd need to consider and implement on the software and perhaps hardware side?

I'm still not really understanding what I would actually need to do to ensure interference is low. Would it mean turning Wi-Fi off or put it in standby mode (is this even possible on the SparkCore?) whenever I want to use BLE? Things like that?

I guess I should give you a use case of why I want to use BLE in my project and hope that it helps:

Let's say I'm detecting the temperature of the inside of my house and to be able to control some RGB lights as well from a web interface/iOS application.

If I lose my Wi-Fi connection, I can obviously no longer control these lights.

This is when I would then want the ability to send over the exact same commands via Bluetooth instead in the event the connection is not available or if I'm out and about (let's say my project would be in similar size to a wearable device).

@gotnull, the documentation for the Core’s SPI is here. As for the BLE, I suggest you do a search in the Community for the term “BLE”. One item that comes upon, among many is:

Your use case is feasible and I suggest you take as much from the searches as possible and get some code together. When you face some obstacles, post here for help :smile:

1 Like

Thanks again for the help @peekay123. I’ll be sure to use the search feature more often from now on :smile:

Really appreciate the help so far!

2 Likes