6

I am developing an application where an Arduino Pro Mini communicates with a 12-bit ADC over SPI. The communication is one-way, meaning that the ADC will only send data back to the Arduino, not receive any. The MOSI pin is therefore not required in my application, only SCK and MISO.

I wish to know if there is a way to have the Arduino SPI library ignore the MOSI pin, and controlling the clock pin directly. The ADC requires 16 clock cycles to perform one conversion, sending the data back on the last 12 clock cycles. The way I have implemented it is by using SPI.transfer16() to get 16 clock cycles, and storing the return value in a 16bit variable. The downside to this is that the MOSI pin is driven, and I can therefore not use it for other purposes. I would very much like to be able to generate 16 clock cycles without the need for driving MOSI. Any ideas?

9
  • 1
    SPI devices communicate in full duplex mode. Cant you use other interfaces that use less wires in their standard? Nov 5, 2016 at 13:33
  • Switching it to an input should disconnect it from SPI. Otherwise, it will be MOSI. Nov 5, 2016 at 13:37
  • 1
    You could always use bitbanging in the form of shiftIn.
    – Gerben
    Nov 5, 2016 at 14:35
  • @IgnacioVazquez-Abrams That would be a good solution if I wanted to use the MOSI pin as an input. However, I require it to be an output.
    – Fulcrum
    Nov 5, 2016 at 14:39
  • @Gerben That looks viable. But I worry that it might not be as reliable as the hardware implementation.
    – Fulcrum
    Nov 5, 2016 at 14:41

2 Answers 2

2

In microcontrollers, the GPIO pins have a multiplexer to select what the pin is used for. When you use the Arduino SPI library, the initialization function will set the multiplexer to MOSI for that pin. You should be able to run your own initialization for that pin and overwrite whatever the SPI initialization function did. Just make sure to call your initialization after SPI.begin(). This is the simplest solution.

If that doesn't work for some reason then you can dig into the source code for the Arduino SPI library. This isn't too hard either.

Bitbanging is the hardest solution and shouldn't be necessary for your application.

1
  • This solution worked for me. I wanted to use the MISO pin for DC on a SSD1331 display. I privately modified the AdaFruit library constructor to call pinMode after SPI.begin() and it worked. Jan 12, 2018 at 16:59
0

You are using ADC which I suppose you have no way of changing firmware or anything to modify the protocol.
According to SPI protocol, when Slave receives a byte, it sends byte kind of a two shift registers in circular buffer. So even if your ADC finish the conversion it wont start communication protectively the protocol doesn't allow it.
In case if you have other ADC IC which is programmable you can implement your protocol but it wont be SPI it will be your own protocol, so be assure of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.