I'm trying to work with an SPI-like device (it's a series of shift registers controlling LEDs and reading some buttons in a premade package), using my N+2.
The device has a memory map of 12 bytes light data, and 5 bytes button data, arranged linearly along a single buffer - as I write in the light data, the first five bytes out are the buttons and then the last 7 bytes out are the first 7 bytes from the old light data.
I'm trying to do an SPIBus.ReadWrite() to read the buttons and the lights at the same time. A simple write() works fine - it pushes the garbage button data and then pushes in the correct light data, so the LEDs work properly. However, trying to ReadWrite() results in garbage data getting written to the LEDs.
My code is the following:
public void Refresh() { int Count = 17 * _Modules; //SPIBus.WriteRead(_Buffer, 5, 12, _Buffer, 0, 5, 0); // Doesn't Work SPIBus.Write(_Buffer); // Works, but no input reading _Latch.Write(true); _Latch.Write(false); }
_Buffer is arranged so that bytes 0..4 are the button data to be read in, and 5..12 are the 7 bytes of LED data.
What do I need to change in the WriteRead() so that it can properly write out the LED data *and* read in the button data? I'm on firmware 4.2, and Visual Studio 2010