Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

SPI Help

spi

  • Please log in to reply
1 reply to this topic

#1 Sukasa

Sukasa

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationNanaimo, BC

Posted 19 July 2014 - 08:05 PM

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



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 20 July 2014 - 01:41 PM

Hi Sukasa,

If you pass in two separate buffers (one for reading, one for writing), does that fix the issue for you?

byte[] _ReadBuffer = new byte[LEN_OF_BUFFER];
byte[] _WriteBuffer = new byte[LEN_OF_BUFFER];
Chris





Also tagged with one or more of these keywords: spi

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.