# Can Arduino MISO be set as output?

So I designed a PCB which consists of an atmega328 controlling a digital potentiometer (MCP4131) using SPI. I stupidly connected the pot's i/o to the MISO (master in, slave out) pin on the arduino instead of the MOSI (master out, slave in) pin. The SS and SCK pins are connected correctly. Needless to say, I haven't been able to make the pot behave as it should, because i can't get the arduino to talk to it.

I tried going into the Arduino SPI library and, in the function begin(), changing the line

pinMode(MOSI,OUTPUT);


to

pinMode(MISO,OUTPUT);


But, this doesn't do the trick. On my scope, I can see the bits being sent when the pot is hooked up properly (on my breadboard). If I could rip up the trace on my PCB and solder a jumper to the right pin on the arduino, that would be a fine workaround. But I'd rather be able to do it in software.

I don't have much experience with SPI. I'm currently researching it but haven't found anything useful on the web. Any thoughts on making the MISO pin switch to "MOSI"?

The Arduino shiftout() is a software/bitbanged spi implementation. You can use that instead of the spi library.

• Awesome. That was way easier than I anticipated. Thanks! – Ryan Tuck Jan 31 '13 at 20:05
• So actually, the signal hasn't been working with my chip. It looks like 5V is the default for MOSI, whereas 0V is the default for shiftOut. My scope shows that the data is being transferred, but the pot isn't responding. It seems that, if I could invert the shiftOut message being sent to the pot, that all would be well. Thoughts? – Ryan Tuck Jan 31 '13 at 23:43
• It shouldn't invert, but use data = ~data to do a bitwise invert of your 8 bit data variable. Decimal 177 in binary 0b10110001 would become 0b01001110 (78). – Passerby Feb 1 '13 at 7:18

If you want to use the SPI module built-in to the microcontroller, you have to use the pins they choose. They are hard wired.

However, you can also use the same pins as general purpose I/O, which means you can bit bang it instead of using the SPI library, but that is significantly more work in the software. You might be able to find an existing library somewhere to help you, but personally I would spin or mod the PCB and call it a lesson learned.

• Thank you, Karl. I'll just solder a manual pot on and hope that the next revision will work with the traces to the right pins. Then, when I have time, I'll figure out bit-banging. – Ryan Tuck Jan 31 '13 at 18:08

Absolutely see shiftout and manual spi bit bang