How to read from a register using software SPI, presumably shiftin()
?
It works using the builtin SPI library + hardware SPI.
I seem to be able to write but not read using manual shiftin()
/shiftout()
. I need to do this because I need a version of this to work on a device that doesn't have hardware SPI. I always read out 0x00000000
using shiftin()
as below, but the SPI hardware/library works as expected.
(yes, I've double checked the pin numbers). LIS_MISO_PIN = 12.
// this works (write):
SPI.transfer(WriteAddr);
SPI.transfer(Data);
// this works (write):
shiftOut(LIS_MOSI_PIN, LIS_SCK_PIN, MSBFIRST, WriteAddr);
shiftOut(LIS_MOSI_PIN, LIS_SCK_PIN, MSBFIRST, Data);
// this works (read):
SPI.transfer(Reg | 0x80);
*input = SPI.transfer(0x00);
// does NOT work, as well as various permutations:
shiftOut(LIS_MOSI_PIN, LIS_SCK_PIN, MSBFIRST, Reg | 0x80);
*input = shiftIn(LIS_MISO_PIN, LIS_SCK_PIN, MSBFIRST);
LIS_MISO_PIN
set asINPUT
? Does your device use SPI mode 0?