SPI clock frequency ?

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Oliv'
Posts: 13
Joined: Fri Oct 30, 2015 9:18 am

SPI clock frequency ?

Post by Oliv' » Sun Nov 01, 2015 12:31 pm

Hi,

I playing a bit with the SPI communications but something is wrong with clock speed, I don't know if it comes from me or the Wipy

If did not made any mistake, I set the SPI link to baudrate=6400, then when I measure the clock with an oscilloscope I get 80,6 kHz
If I set the SPI link to baudrate=640000, then when I measure it with an oscilloscope I get 5 kHzI
If I set the SPI link to baudrate=6400000, then when I measure it with an oscilloscope I get 1.3 MHz

Code: Select all

spi = SPI(0, SPI.MASTER, baudrate= 6400000, polarity=0, phase=1)
toSend = bytearray(3)
toSend[0] = 0x80
toSend[1] = 0x80
toSend[2] = 0x80
while True:
	spi.write(toSend)
	time.sleep_us(60)

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: SPI clock frequency ?

Post by danicampora » Sun Nov 01, 2015 1:21 pm

Hi, is the WiPy, the internal clock divider cannot generate any given baudrate. This needs to be added to the docs. Input clock is 80MHz, and there's a divider which can take values from 1 to 32768. Typically you'd set the SPI clock to values like 1MHz, 2MHz, 10MHz, etc.

Do you need such special SPI clock values for a reason?

Cheers,
Daniel

Oliv'
Posts: 13
Joined: Fri Oct 30, 2015 9:18 am

Re: SPI clock frequency ?

Post by Oliv' » Sun Nov 01, 2015 2:28 pm

Thanks Dani,

At the beginning, I wanted to modify this library to drive WS2812 with SPI+DMA but it did not work, so I tried to write some tests which need 6,400,000 Hz
But event at 3,200,000 (80000000/3200000=25) I do not have the request frequency : I have 20 kHz

Also from my first post 6400 and 640000 are valid :(

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: SPI clock frequency ?

Post by danicampora » Sun Nov 01, 2015 3:41 pm

Hi!

Great the WS2812 is something that would be awesome to drive with the WiPy :-). Let me check what's going on with the clock frequency and I'll get back to you ASAP.

Cheers,
Daniel

nui_de
Posts: 40
Joined: Fri Oct 23, 2015 3:27 pm

Re: SPI clock frequency ?

Post by nui_de » Sun Nov 01, 2015 7:40 pm

Hi!,

isn't there a WS2812 library already?
http://forum.micropython.org/viewtopic. ... ixel#p3778

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: SPI clock frequency ?

Post by danicampora » Sun Nov 01, 2015 11:18 pm

Hi Oliv'

You were right, there was a bug in the clock setting routine. I have fixed it and pushed to micropython master. The fix should be available here: http://micropython.org/download/ in around 2 hours. Actually the clock resolution is quite good, so you should be able to set the value you need. Please keep us posted regarding the WS2812 driver :-)

Thanks for the bug report.

Cheers,
Daniel

Oliv'
Posts: 13
Joined: Fri Oct 30, 2015 9:18 am

Re: SPI clock frequency ?

Post by Oliv' » Mon Nov 02, 2015 4:02 pm

danicampora wrote: You were right, there was a bug in the clock setting routine. I have fixed it and pushed to micropython master. The fix should be available here: http://micropython.org/download/ in around 2 hours.
It works, thanks !
danicampora wrote: Actually the clock resolution is quite good, so you should be able to set the value you need.
I am a bit lost about the CC3200 documentation... In the datasheet, it is 20 Mhz max (20 pf capacitance). In the technical reference manual there is no such limitation : do you know the capacitance on the PCB for the Wipy clock ?

By the way, finding a bug in TI's HAL files....well done, it works :P . Regarding the WS2812 I think that my breadboard wires have to much capacitance for testing and I need to wire it better because my MOSI signal is ugly at such speeds. Stay tuned :)
nui_de wrote: isn't there a WS2812 library already?
Yes there is, see my second post ;) I am adapting it to this MCU (no floating point, SPI0, MSB first...).
Also I think that less computation power can be required by using 32 bits transferts instead of 8, even if it requires a bit more memory

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: SPI clock frequency ?

Post by danicampora » Mon Nov 02, 2015 4:17 pm

I believe the limitation comes from the fact the source clock is 40MHz (directly from the xtal), and the minimum divider is 2, hence 20MHz.

According to my calcs, you should set the clock to 8MHz, and use 8 bytes per color (1 byte SPI byte per color bit). The SPI of the CC3200 works in a way that there are always 2 dead clock cycles between transfers (you can see that in the scope, but also confirmed by TI). So, set the transfer to 8 bits. To send a low bit, write byte = (0b11100000 + 00 dead cycles), and to send a high bit write byte = (0b11111100 + 00 dead cycles), and that should work.

Keep us posted! :-)

Cheers,
Daniel

Oliv'
Posts: 13
Joined: Fri Oct 30, 2015 9:18 am

Re: SPI clock frequency ?

Post by Oliv' » Mon Nov 02, 2015 11:14 pm

danicampora wrote:I believe the limitation comes from the fact the source clock is 40MHz (directly from the xtal), and the minimum divider is 2, hence 20MHz.
Ok, thanks
danicampora wrote: there are always 2 dead clock cycles between transfers (you can see that in the scope, but also confirmed by TI).
You are right, I opened the CC3200 data sheet because of this "surprise". So your calcs are ok ;)

But, by default there is a pull-up on MOSI...
I spent 5 minutes on installing and testing workflow (really easy, thanks !), 10 min in trying to understand HAL without success, 2 in adding a dirty "PinConfigSet(PIN_07, PIN_STRENGTH_4MA, PIN_TYPE_STD_PD);" in SPIConfigSetExpClk (spi.c) and... 1.5 hours to find that the revision embedded in github/wipy does not include your SPI correction, which is in HEAD of github/micropython ! Shame on me :lol:

By the way it seems to work, but I need to check with my LED matrix and not a single ws2812 as now.
So:
  • Is there an easy way to select pull up/down for MOSI ? Using "Pin( mode=Pin.ALT, pull=Pin.PULL_DOWN, drive=Pin.MED_POWER, alt=7)" after initializing SPI seems not working
  • How does HAL work ? Is there any documentation ? I was unable to track after the function after MAP_SPIConfigSetExpClk

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: SPI clock frequency ?

Post by danicampora » Mon Nov 02, 2015 11:21 pm

Hi!

Cool that it works :-)
Is there an easy way to select pull up/down for MOSI ? Using "Pin( mode=Pin.ALT, pull=Pin.PULL_DOWN, drive=Pin.MED_POWER, alt=7)" after initializing SPI seems not working.
Ummm, that should work. Let me analyze it...

Post Reply