Hi:
I am working on adding an spi device and only the first write after initialization appears corrupted, with subsequent writes being correct. Perhaps I do not have the latest firmware or drivers. Since this is simply writing, it is my understanding that it should not depend on if a device is attached. My full code did not work, so I have reduced this to this simplest task hoping that someone might help.
Here is the code, and at the bottom are the versions of the tool chain.
Option Explicit OnOption Strict OnImports System.IOImports System.ThreadingImports System.IO.PortsImports Microsoft.SPOT'Imports Microsoft.SPOT.Hardware'Imports Microsoft.SPOT.Net.NetworkInformationImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoImports Microsoft.VisualBasic.ConstantsNamespace TestADC7799 Public Module Module1 Dim _spi As SPI Sub Main() Debug.Print("Startup") SetupSPI() For j As Byte = 0 To 254 Write7799Reg(j) Next j Debug.Print("Finished") End Sub ''' <summary> ''' Configures SPI parameters particular to ths ADC 7799 ''' </summary> ''' <remarks></remarks> Sub SetupSPI() Dim _csht As UInteger = 1 ' _chipselect holdtime mS (time that CD must remain active before unselecting, or time after the read write completion) Dim _csas As Boolean = False ' Chip select active state Dim _csst As UInteger = 10 ' Chip select Setup Time mS (time acter cs before reading) Dim _ce As Boolean = True ' If true, data is sampled on the rising edge, else falling edge Dim _cis As Boolean = True ' click idle state, high if true Dim _cr As UInteger = 100 ' clock frequency in kHz Dim spiConfig As New SPI.Configuration(Pins.GPIO_PIN_D10, _csas, _csst, _csht, _cis, _ce, _cr, Microsoft.SPOT.Hardware.SPI.SPI_module.SPI1) _spi = New SPI(spiConfig) End Sub Sub Write7799Reg(something As Byte) Dim b(0) As Byte Debug.Print("Writing Register 1 byte " & something.ToString("X")) b(0) = something _spi.Write(b) End Sub End ModuleEnd Namespace
The output window shows:
Pinging... TinyCLR
HalSystemInfo.halVersion: 4.2.0.0
HalSystemInfo.halVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC
HalSystemInfo.oemCode: 34
HalSystemInfo.modelCode: 177
The logic analyzer shows that the initial idle state of the CLK line does not match the settings.
My code is attached.