3
\$\begingroup\$

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"?

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Awesome. That was way easier than I anticipated. Thanks! \$\endgroup\$
    – ryantuck
    Commented Jan 31, 2013 at 20:05
  • \$\begingroup\$ 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? \$\endgroup\$
    – ryantuck
    Commented Jan 31, 2013 at 23:43
  • \$\begingroup\$ 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). \$\endgroup\$
    – Passerby
    Commented Feb 1, 2013 at 7:18
3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – ryantuck
    Commented Jan 31, 2013 at 18:08
2
\$\begingroup\$

Absolutely see shiftout and manual spi bit bang

\$\endgroup\$

Your Answer

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

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