I'm trying to copy some pBasic code from a Parallax Mouse Sensor Kit into something that will work on my Arduino. I think I've got everything nailed down except for one piece: Shiftin
The pBasic code as an "MSBPOST" option which the Arduino does not appear to have.
Anyone know how to implement this functionality on an Arduino?
I don't know that pBasic stuff but have you tried LSBFIRST? What does the MSBPOST option mean? That the MSB is the last bit? If yes, than LSBFIRST is your choice.
I don't see how I would implement this functionality with the SPI library - my integrated circuit has one datapin and I'd somehow need to replace the datapin with a MOSI, MISO, and maybe even a slave select (although it looks like the last is optional if there's only one ic).
mbackus:
I took a look at your page. It shows the SPI library using 4 pins whereas the shiftin command only uses 2 (which is how my hardware is set up).
I don't see how I would implement this functionality with the SPI library - my integrated circuit has one datapin and I'd somehow need to replace the datapin with a MOSI, MISO, and maybe even a slave select (although it looks like the last is optional if there's only one ic).
You don't need MISO, becase the slave isn't outputting and the master isn't receiving. MISO is what you need if you want to use shiftIn.
You don't need slave select because you only have 1 slave.
Quite right. I use SPI to shift out to a 595 shift register. It gives you clock and data. You can configure the clock to be on the leading or trailing edge and normally high or normally low.
Now that I look at the documentation (and it might have saved time to put the link in your first post) it doesn't seem that SPI will help here, because the data line is bi-directional.
It looks like you will have to choose a pin for the data and clock (any pins) and configure the clock as output. Then configure the data as output and do a ShiftOut to send the address (one byte) then change the data pin to an input, and use ShiftIn to get the results back.
I finally got it working, and it's working really well. I was forgetting to toggle the dataline's pinmode between input and output before the shift commands. Thanks so much.