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.
I'm trying to figure out SPI on the netduino with this code:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.IO.Ports;
namespace NetduinoApplication1 {
public class Program {
public static void Main() {
SPI spi_port = new SPI(new SPI.Configuration(
Pins.GPIO_NONE, // Chip select pin
false, // false - CS active state is low
0, // CS setup time in ms
0, // CS hold time
false, // false - Clk low on idle
false, // false - Data valid on falling edge
100, // Clock rate in kHz
SPI_Devices.SPI1 // SPI Module
));
byte[] readBuffer = new byte[2];
while (true) {
spi_port.WriteRead(new byte[] { 0x00, 0x55 }, readBuffer);
//Thread.Sleep(1);
}
}
}
}
I have problem with:
1. Clock rate adjustment. What clock speed is supported by Netduino?
2. 20us before the data transfer, the clock line is weakly pulled-up for about 40us. This gave me an extra unwanted clock edge. Is it possible to remove this?
I'm trying to figure out SPI on the netduino with this code:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using System.IO.Ports;
namespace NetduinoApplication1 {
public class Program {
public static void Main() {
SPI spi_port = new SPI(new SPI.Configuration(
Pins.GPIO_NONE, // Chip select pin
false, // false - CS active state is low
0, // CS setup time in ms
0, // CS hold time
false, // false - Clk low on idle
false, // false - Data valid on falling edge
100, // Clock rate in kHz
SPI_Devices.SPI1 // SPI Module
));
byte[] readBuffer = new byte[2];
while (true) {
spi_port.WriteRead(new byte[] { 0x00, 0x55 }, readBuffer);
//Thread.Sleep(1);
}
}
}
}
I have problem with:
1. Clock rate adjustment. What clock speed is supported by Netduino?
2. 20us before the data transfer, the clock line is weakly pulled-up for about 40us. This gave me an extra unwanted clock edge. Is it possible to remove this?
Hello Stephen,
Currently I use a clock at 1000 kHz with my nokia 3310 LCD with success,
1. Clock rate adjustment. What clock speed is supported by Netduino?
We've used a variety of clock speeds with success (internally, the .NET MF runtime divides the 48MHz clock into a small counter and then multiplies that counter to match your speed as closely as possible). What clock speed are you looking for?
2. 20us before the data transfer, the clock line is weakly pulled-up for about 40us. This gave me an extra unwanted clock edge. Is it possible to remove this?
Hmm, curious. The SPI code comes straight from Atmel and Microsoft, but we can look into this. I'd have to look at some native code SPI samples to see if this is a chip implementation or CLR implementation item. But if you need us to, we can schedule some time to analyze this further. Are you having data communication isssues on SPI because of this?
We've used a variety of clock speeds with success (internally, the .NET MF runtime divides the 48MHz clock into a small counter and then multiplies that counter to match your speed as closely as possible). What clock speed are you looking for?
Hmm, curious. The SPI code comes straight from Atmel and Microsoft, but we can look into this. I'd have to look at some native code SPI samples to see if this is a chip implementation or CLR implementation item. But if you need us to, we can schedule some time to analyze this further. Are you having data communication isssues on SPI because of this?
Chris
Regarding clock speed, when I try 1000 Khz, I see 550.66 Khz on my oscilloscope ...
Cpu.GlitchFilterTime = new TimeSpan(0, 0, 0, 0, 100); //100 ms
...
It works fine on emulator, but it raise a exception at first line on netduino :
"An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll"
Microsoft built two GlitchFilers. One is more resource-hungry and supports user-defined GlitchFilterTimes. The other is less resource-hungry and does not support user-defined GlitchFilterTimes. In the case of the AT91SAM7X512 microcontroller on the Netduino, .NET Micro Framework uses the latter.
Basically, this less resource-hungry GlitchFilter samples a pin multiple times to make sure that the signal change wasn't an electrical glitch. Crude but effective--and very fast.
Are you having data communication isssues on SPI because of this?
I have not tried connecting the SPI to a device yet. I think the extra clock edge will cause communication issues for devices that do not have the Chip Select line connected.
Okay, just to make sure I understand this right... The SPI clock is working properly for you now, correct?
If not, I want to make sure I get a bug report files so we can investigate...
My SPI works because I use 1 Mhz clock. Because netduino is the master clock, I decided to use that freqency. If the slave doesn't support freqency above 150khz, we will probably have a issue.
But it's not my case.