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 issue: bad first write

spi vb netduino plus 2

  • Please log in to reply
2 replies to this topic

#1 rockybooth

rockybooth

    Member

  • Members
  • PipPip
  • 16 posts

Posted 16 November 2013 - 09:23 PM

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:

Assembly: Microsoft.VisualBasic (1.0.0.0)
Assembly: Microsoft.SPOT.Graphics (4.2.0.0)
Assembly: SecretLabs.NETMF.IO (4.2.0.0)
Assembly: SecretLabs.NETMF.Hardware.AnalogInput (4.2.2.0)
Assembly: SecretLabs.NETMF.Hardware (4.2.0.0)
 
MFDeploy reports:

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.

 

 

 

Attached Files



#2 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 17 November 2013 - 12:39 AM

I had this problem with Firmware V 4.2.2.2. Re-flashing to V 4.2.2.1 fixed it. See Post #230
 
I also posted a question about a possible bug, but no response,


#3 rockybooth

rockybooth

    Member

  • Members
  • PipPip
  • 16 posts

Posted 17 November 2013 - 09:33 PM

Thanks Baxter:

In looking at both the logic analyzer and scope, I have attached a scope trace showing what happens.  Ignore the yellow (reply from device or MISO) - the green is CS(bar), pink MOSI, and blue is the clock. You can see that the clock goes low before CS, but then after CS seems to go high impediance (made an input?), then finally reaches a "1" and works fine after that. However, the external device (and logic probe) thinks the drift higher is a clock edge, and thus gets nine clock cycles, not eight.  

Adding an external pull up on the clock seems to help.

This seems a clear bug in the SPI, but one that will only show up on the first write.  Some applications and external devices may not show a problem. The AD7799 that I am targeting has Schmit triggers on its inputs, so the slow rise work "just fine" (not).

It would be nice to get a response from Chris on this.  

Rocky

Attached Files






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.