Why does the SPI library only have WriteRead()?
#1
Posted 03 November 2011 - 09:14 PM
#2
Posted 03 November 2011 - 09:41 PM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#3
Posted 03 November 2011 - 11:14 PM
-- H.L. Mencken, "What I Believe"
#4
Posted 07 November 2011 - 05:50 PM
#5
Posted 22 November 2011 - 06:44 PM
Here's a screenshot from the logic analyzer:
I then moved the shield over to my Netduino and ran my code. I distilled my code down to the following few lines that should read in the data:
while( true) { var _spi_config = new Microsoft.SPOT.Hardware.SPI.Configuration( SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D7, false, 0, 0, true, false, 1000, Microsoft.SPOT.Hardware.SPI.SPI_module.SPI1); byte[] outval = new byte[4]; _spi.WriteRead( new byte[] { 0x00, 0x00, 0x00, 0x00 }, outval); }
Here's what my logic analyzer showed me:
and zoomed in:
I must have done something dreadfully wrong with WriteRead, but from what I gathered from everyone's suggestions, I should "write" out 4 bytes to read back 4 bytes...
#6
Posted 23 November 2011 - 02:05 AM
-- H.L. Mencken, "What I Believe"
#7
Posted 23 November 2011 - 01:29 PM
The image from the logic analyzer looks like you switched the clock and chip select pins.
It looks strange, indeed, but please note that I merely moved the shield from the arduino (working) to the netduino.
The only variable is the SPI code, which makes me think I either didn't initialize the SPI object properly, or
WriteRead() isn't working as expected, either because it's not designed to work the way I need it to, or because
I'm using it incorrectly.
#8
Posted 23 November 2011 - 01:37 PM
Try this:
while( true) { var _spi_config = new Microsoft.SPOT.Hardware.SPI.Configuration( SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D7, false, 0, 0, true, false, 1000, Microsoft.SPOT.Hardware.SPI.SPI_module.SPI1); byte[] outval = new byte[4]; _spi.WriteRead( new byte[] { 0x00, 0x00, 0x00, 0x00 }, outval); }
var _spi_config = new Microsoft.SPOT.Hardware.SPI.Configuration( SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D7, false, 0, 0, true, false, 1000, Microsoft.SPOT.Hardware.SPI.SPI_module.SPI1); _spi.config = _spi_config; // Actually loads the SPI config while( true) { byte[] outval = new byte[4]; _spi.WriteRead( new byte[] { 0x00, 0x00, 0x00, 0x00 }, outval); }
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#9
Posted 23 November 2011 - 02:14 PM
The image from the logic analyzer looks like you switched the clock and chip select pins.
So actually, I didn't look closely enough at the sample arduino code. His library is bitbanging DIO, and not using an SPI library. I assumed too much by looking at SPI-related variables like MISO and SCLK and didn't look deep enough. I have to look at the NETMF SPI info, because the pins actually might be swapped on the board... who knows? I'll be more thorough now and will post up what I find. Thanks for making me think twice about the setup.
#10
Posted 23 November 2011 - 02:16 PM
Try this:
var _spi_config = new Microsoft.SPOT.Hardware.SPI.Configuration( SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D7, false, 0, 0, true, false, 1000, Microsoft.SPOT.Hardware.SPI.SPI_module.SPI1); _spi.config = _spi_config; // Actually loads the SPI config while( true) { byte[] outval = new byte[4]; _spi.WriteRead( new byte[] { 0x00, 0x00, 0x00, 0x00 }, outval); }
That's what my "real" code does. When I distilled it for the post, I accidentally reinstantiated the object every time through the loop.
#11
Posted 23 November 2011 - 02:23 PM
So actually, I didn't look closely enough at the sample arduino code. His library is bitbanging DIO, and not using an SPI library. I assumed too much by looking at SPI-related variables like MISO and SCLK and didn't look deep enough. I have to look at the NETMF SPI info, because the pins actually might be swapped on the board... who knows? I'll be more thorough now and will post up what I find. Thanks for making me think twice about the setup.
Back to the drawing board... the shield library uses the same pins. I will start writing a bitbanging class to deal with shield communication, unless anyone can think of something I'm doing wrong here...
#12
Posted 23 November 2011 - 02:46 PM
Pin Connections
- 13 - SCK
- 12 - SO
- 10 - CS1
- 9 - CS2
- 8 - CS3
- 7 - CS4
- 6 - LED1
From Netduino specs (http://www.netduino....duino/specs.htm):
digital pins 11-13: SPI MOSI, MISO, SPCK
So, with managed SPI, pin 11 is MOSI, pin 12 is MISO and 13 is SCK.
Any other pin (except pin 4 due to a bug) can be used as chip select.
I don't quite understand why it has 4 chip selects though.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#13
Posted 23 November 2011 - 02:50 PM
So, with managed SPI, pin 11 is MOSI, pin 12 is MISO and 13 is SCK.
Any other pin (except pin 4 due to a bug) can be used as chip select.
Yes, this is what I saw as well, so figured the SPI library should have worked.
I don't quite understand why it has 4 chip selects though.
It has four chip selects because the shield has four MAX31855s on it, one for each thermocouple.
#14
Posted 23 November 2011 - 03:59 PM
Thanks for the replies, everyone!
I'm not sure if it's useful or not to post this port somewhere (github?), so just let me know if you need / want it.
#15
Posted 23 November 2011 - 04:26 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users