Created Fri, 15 Jul 2011 18:57:43 +0000 by voyager
Fri, 15 Jul 2011 18:57:43 +0000
Can anyone tell me how to set the speed of the SPI interface to 48MHz ?
When using the mbed compiler i can set the values like this:
spi.format(8,3); // 8 bit spi mode 3
spi.frequency(48000000); // 48Mhz SPI clock
Is there something useful like this with the chipKIT ???????
Sat, 16 Jul 2011 15:06:22 +0000
It is really amazing how many people read this topic. But nobody answers. Is it because most of them are clueless to this subject or just readers checking the forum? Not even the creators of the chipKITs seem to have knowledge about SPI. Well nice boards with any use.
Sun, 17 Jul 2011 00:05:53 +0000
A simple search in library sources reveals the sources SPI.h and SPI.cpp, where the SPI class is located. What you're looking for is called SPIClass::setClockDivider(), which you should access like SPI.setClockDivider(dividerValue). All this method does is setting a value of SPI2BRG (SPI2 baud rate generator).
Now open the documentation of PIC32, the file that describes SPI module: http://ww1.microchip.com/downloads/en/DeviceDoc/DS-61106F.pdf Browse to page 23-28 and see the formula that shows how the actual clock is calculated. The formula also says that the maximum frequency you can have for SPI clock is Fpb/2, which, in case of Fpb = 80, is 40MHz.
It's amazing how little time it takes to find this out by oneself.
Mon, 18 Jul 2011 19:09:26 +0000
@ svofski
Thanks for your repartee. My initial idea was not to spend hours reading data sheets and applications. Instead of that i thought of using the community to get a fast and working answer from people who have had the same problem and have worked it out and are willing to help others. Okay thanks for your instructions. I tried what you suggested with the result that it is not working. Your solution would have been really too easy. My measurements with a logic analyzer did not show any effect changing the frequency on the SPI lines. Maybe i have a faulty board. But i am not interested in searching the failure. All i needed for my project was a cheap board with a color GLCD board. Instead of getting headache and losing time i spent some money and switched to a mikroMMB board for PIC32. It works perfect. The chipKITs will be kept in a dark place for a long long time. It was a good idea but not useful for me.
Thanks for your help.
Mon, 18 Jul 2011 22:36:24 +0000
No probs, whichever suits you better.. On a Max32 I have 2 SPI units set up at 36MHz with the master clock running at 72MHz and they seem to be healthy, although I can't tell how completely healthy they are, yet. Maybe you've missed some pesky bit in some register.
Tue, 26 Jul 2011 23:38:25 +0000
..try to set the mcu clocks to 96/96MHz.. you'll get 48MHz spi.. p.
Tue, 26 Jul 2011 23:57:36 +0000
..try to set the mcu clocks to 96/96MHz.. you'll get 48MHz spi.. p.
This could work but it seems to be as close to the limit as it gets.
The minimum clock period for SCKx is 40 ns. Therefore, the clock generated in Master mode must not violate this specification.
Same goes for slave. 40ns = 25 MHz. I tried 36MHz and it seems to work fine, but it's already in the overclocking area.
Sat, 30 Jul 2011 21:50:25 +0000
..I've run it for weeks 120/120MHz 2 waitstates. Not tested all the pripherals, though. Just set 96/96 and you will see.. P.
Sun, 31 Jul 2011 00:27:48 +0000
..I've run it for weeks 120/120MHz 2 waitstates. Not tested all the pripherals, though. Just set 96/96 and you will see.. P.
Cool! Thanks for the info.