Sharing MISO with SoftwareSerial Rx since they are both Input

I am trying to share PIN12 for both:

  • MISO of an SD card logger module

and

  • Rx of a software serial Wifi Module.

In concept they should work since both are modules_Output to Arduino_Inputs i.e: both sending data to arduino:

1- SD card is used to log data and will not be sending any data after setup at: if SD.Begin

2- Arduino will be analyzing any received data on PIN12 looking for a specific 'keyword' and only read few charaters that follows that 'keyword' when found.

The sketch works fine processing the wifi commands if the SD card module is not plugged, but when i plug SD card (and restart), wifi orders are not processed at all.

What am I missing here?

(sketch is too long and complicated to include here, if the idea is not clear, I will try to simplify the sketch and post it.)

Thanks

What am I missing here?

Besides the fact that you can NOT share pin 12?

Why not, sharing should be transparent to Arduino. Arduino is just readong and processing whatever is received on that PIN. and while the SS is low the SD card will ignore what is received.

Unless someone tells me that SPI will not allow Arduino to read from PIN12 unless an SS is high, which I really doubt, because it works with the same sketch when the sd card is physically not connected.

Unless someone tells me that SPI will not allow Arduino to read from PIN12 unless an SS is high, which I really doubt, because it works with the same sketch when the sd card is physically not connected.

When you are using SPI, you have no control over when the slave will send data (the SO part of MISO). So, what is going to happen if the slave sends data while the SoftwareSerial instance is active?

Thank you for the reply, but this should not be a problem, since:

1- No data is expected to be sent from the SDcard/SlaveOut(SO) to the Arduino/MasterIN(MI) since no reading requests are ordered by master.

2- As long a SS (aka CS) is not activated(low) nothing should be sent from the SD card SO to MI

3- Even if something is received by MasterIn, it will not pass the 'Keyword' validation check and will be just ignored and dumped.

So it should work, but it doesn't?

You have no other pins to use for soft serial rx? The analog inputs can be use for digital I/O pins.

I see a problem using Pin12 for RX - in serial transmission the idle condition is HIGH and that is set by the sending device, not the Arduino. I reckon the HIGH for serial-idle will interfere with SPI.

...R

Robin2:
I see a problem using Pin12 for RX - in serial transmission the idle condition is HIGH and that is set by the sending device, not the Arduino. I reckon the HIGH for serial-idle will interfere with SPI.

...R

What you are saying is correct, but it should not cause the problem, since as long as CS is not triggered, ISP should not interfere, and this is proven by the sketch working as I want whe the SD card module is unplugged.

What do you think?

boolf:
What do you think?

What I said in Reply #6 - I suspect a serial input will interfere with SPI - but I have not tested it.

...R

Robin2:
What I said in Reply #6 - I suspect a serial input will interfere with SPI - but I have not tested it.

...R

I suspect the same thing, and, since you have NO control over when serial data will arrive, you can NOT be sure that interference will not happen. Just don't do it.

There are Arduinos with more pins, if that is the problem.

MISO works for multiple SPI devices because the SPI standard says that only a device with CS low is allowed to control the MISO wire. (It is up to your master to ensure that it never sets CS low on more than one device.)

Serial data doesn't have that kind of specification. The sender can do whatever it wants at any time. You cannot predict when the device will or will not send data. It expects that there is a direct hard-wired connection between the sender and your Rx pin. The pin is never allowed to float. Under the Serial standard, the sender must hold the pin high or low and cannot ever relax or release the pin for another device to use.

You could add another chip in there to disconnect the serial transmitter when you don't want to listen to it. "Talk to the hand because the ears aren't listening." But that's a terrible idea - when you switch it back on you cannot retrieve what you missed.

You do know the analog pins can be used for digital inputs, don't you?