mc-Things

mc-Products => mc-Module => Topic started by: rudydevolder on August 03, 2016, 01:56:27 am

Title: [SOLVED] SPI problems
Post by: rudydevolder on August 03, 2016, 01:56:27 am
First of all it took me a while to figure out I had to place Spi.Create in the Shared Boot Event() instead of in Sub New()
At least to get some signal out, I don't know why but when I place Spi.create in Sub new() nothing happens on the spi-bus with Transfer.
But placed spi.create in the Shared Boot Event I can see the clock-signal and the CS working but the data is always xFF whatever I try to send and whatever speed or mode I use.
I can clearly see the amount of bytes I've send with the Transfer() command but my logic analyser shows every byte as 0xFF, indeed when I try to connect my WS2801 Leds the only thing I get out of it is plain white and no colors.
Title: Re: SPI problems
Post by: mc-Abe on August 03, 2016, 10:29:35 am
Could you share your code with us? Here is a test I just ran and things seem to be working.

Code: [Select]
Class test
    Shared dev As Spi
    Shared Event Boot()
        dev = Spi.Create(1000000, 0, Pin.Pin2, Pin.Pin3, Pin.Pin4, Pin.Pin5)
    End Event
   
    Shared Event Try() RaiseEvent Every 100 milliSeconds
        Dim payload As ListOfByte = New ListOfByte
        payload.Add(0)
        payload.Add(1)
        payload.Add(2)
        dev.Transfer(payload)
    End Event
   
End Class

I did discover an issue with the mode mapping which we will fix in the next revision.
Title: Re: SPI problems
Post by: rudydevolder on August 03, 2016, 11:37:19 pm
Tried your code, except I used other pins because I soldered the wires already but same result. :'(
I used following Pins: dev = Spi.Create(1000000, 0, Pin.Pin6, Pin.Pin5, Pin.Pin4, Pin.Pin3)
I 've put the output of my logic analyser in attachment.
(http://)
I wonder if the McModule doesn't has hardware SPI because it's using bitbanging now. I know because you can define any pins to do SPI.
I want to steer a set of WS2801 Leds and I know bitbanging has generally issues because the throughput isn't that stable and continuous to command so many LED's at once.


[attachment deleted by admin]
Title: Re: SPI problems
Post by: mc-Abe on August 04, 2016, 01:08:16 am
The processor we are using has a very flexible SPI peripheral that can use any of the pins. That is how you are able to use any pin you want for the SPI functionality. There is not SPI bit-banging going on. Is this output generated from the sample code below? The MOSI line (which i suspect is the SDIO line in your capture) should not be changing unless on a clock edge. Your capture seems rather suspect. As I said there is an issue with the SPI mode. I would try mode 1 instead of mode 0 and see if you get different results?
Title: Re: SPI problems
Post by: rudydevolder on August 04, 2016, 05:22:37 am
I just tried your suggestion mr mc-Abe, but no difference. Tried modus 0 till 4 I can see differences in the polarity of the clock, also switched the MOSI with the CLK line on my logic analyser. But after studying some examples on the internet and making a working example on the SPI on my Feather Huzzah, I can only conclude that the signal is totally off. The only resembling with a correct pattern is that clock is symmetric and the CS line is working but than in my example and on the internet I see mostly bursts of the clock-signal for each byte, and also the typical pattern transmitting the bytes 0, 1, 2, 3, 4 I did in both test are totally off. I give you the working test on my Feather Huzzah in attachment. You can see clearly how the information is correctly interpreted by the analyser and how the clock and Mosi line behaves in time.

[attachment deleted by admin]
Title: Re: SPI problems
Post by: mc-Abe on August 04, 2016, 01:00:35 pm
The bursts of clock you see on other examples is due to delay between every byte transmitted by the processor. We have taken measures to ensure no delay between each byte to maximize the SPI throughput and minimize power consumption.

I believe there is an issue with your code. Could you share your code. Here is sample code I ran and what my Logic Analyzer is outputting. It is exactly as I would expect it. I am not sure where things are going wrong for you.

Code: [Select]
Class test
    Shared dev As Spi
    Shared Event Boot()
        dev = Spi.Create(1000000, 1, Pin.Pin6, Pin.Pin5, Pin.Pin4, Pin.Pin3)
    End Event
   
    Shared Event Try() RaiseEvent Every 100 milliSeconds
        Dim payload As ListOfByte = New ListOfByte
        payload.Add(0)
        payload.Add(1)
        payload.Add(2)
        payload.Add(3)
        payload.Add(4)
        dev.Transfer(payload)
    End Event
End Class
Title: Re: SPI problems
Post by: rudydevolder on August 05, 2016, 05:36:14 am
It works  ;) ;D  after swapping the MOSI and MISO line !

There must be an error in the documentation it says: in chapter 12.3
The Create method creates an object that describe the path to a chip by specifying Speed, Mode, SCLK, MOSI, MISO and SC.
But it's, Speed, Mode, SCLCK, MISO, MOSI, CS

I don't know why I got a signal on the input but I guess it's just because nothing was connected, so I thought I was really displaying the info from the MOSI line while it was the MISO connection.

I'm so happy to know that SPI is done by hardware and not bitbanged! Love it! Tomorrow I will start to experiment with the WS2801 LED's ! Yippeee

Thanks mr. mc Abe. And thanks mc Things for the hardware SPI, much better!
Title: Re: [SOLVED] SPI problems
Post by: mc-Abe on August 08, 2016, 09:55:26 am
I'm glad you got this working. In future please use the "Method format" chapter at the end of mc-Script User Guide which has API definitions. This section and the auto complete feature in mc-Studio are authoritative sources.
Title: Re: [SOLVED] SPI problems
Post by: rudydevolder on August 13, 2016, 11:33:34 am
Just found out that the Voltage-level of the output pins is typical 3V and not 3V3, so I need to buffer my SPI-CLCK and MOSI signal to steer my 5 Volt WS2801 LED's  :-\

I will use the: SN74HCT125N I guess?

Title: Re: [SOLVED] SPI problems
Post by: mc-Abe on August 17, 2016, 09:19:38 am
The module is powered from a CR2032 battery which has a nominal voltage of 3V. So it would be expected that you would see 3V on the SPI lines. What you have suggested should work for you.