Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
1,840 Views

Improving Galileo SPI performance? - SPI.transfer/SPI.transferBuffer

Much of what I understand so far come from this posting: /message/231432# 231432 what's the max speed of galileo SPI ?

I was working on using https://www.sparkfun.com/products/10628 this shield to play MP3s on the Galileo. I was successful using the code from the http://arduino.cc/en/Tutorial/GalileoSampleSequencer Galileo Sample Sequencer (https://gist.github.com/X-Y/7900308 Code Here) and using the Galileo's SD slot, not the shield's.

What I found was that small MP3s played just fine, however, larger MP3s, such as songs, played poorly. It sounded as though only small chunks of the song were playing. After learning that the SPI.transfer and SPI.transferBuffer functions were the problem (they are very slow), I found that increasing the buffer size improved sound quality greatly, but I never got a perfect result.

Has anyone found a way to improve the transfer calls or a workaround to improve performance? Why might these function calls be slow?

6 Replies
Highlighted
Community Manager
7 Views

The SPI calls send data to a Linux driver which does the actual SPI communication. That kernel and IO overhead can add up. Buffer up your data as much as you can. Another factor can be CS/SS pins. If you have to toggle these pins on every transfer, that too can add up. The SPI driver can actually handle the IO10 CS pin for you, but the Arduino code doesn't expose it last I checked. If you have to use CS pins, see if you can keep it low or try using the fast IO feature of pins 2 and 3.

I did some SPI speed experimentation a while ago and never finished it. But here is a snippet I used to enable the SPI driver toggling IO10. You might give it a try. It needs sysfs.h included.

for(int i = 0; i < sizeof_g_APinDescription; ++i) { if (g_APinDescription[i].ulGPIOId == 42) { sysfsGpioSet(g_APinDescription[i].iHandle, 0); break; } }
Highlighted
Employee
7 Views

Hi jjaken

Another thing you can try to improve the performance of the SPI speed is to change the SPI clock divider, by default if set to SPI_CLOCK_DIV4 which correspond to 4MHz. You can increase the speed to 8.33MHz by using in the setup:

setClockDivider(SPI_CLOCK_DIV2);

If you notice an improvement but that is not enough you can change the source code to get higher speeds. The library is located in C:\Arduino-1.5.3\hardware\arduino\x86\libraries\SPI, in the file SPI.cpp change line 129 from maxSpeedHz = SPI_CLK_DEFAULT_HZ << 1; to maxSpeedHz = SPI_CLK_DEFAULT_HZ << 2; in order to get 12.5MHz, or to maxSpeedHz = SPI_CLK_DEFAULT_HZ << 3; to get 25MHZ, but I'm not sure if this changes will affect anything else. I hope you find this useful.

Regards,

 

JPMontero_Intel
Highlighted
7 Views

Hi JPMontero,

I have played with those quite a bit. The sound comes in at different rates depending on the settings. No matter what I tried, I never found a setting that sounded correct. If I recall correctly, the library performs some calculations based on the Arduino's speed and the mp3's bitrate. Those are calculations I don't understand well enough to port.

Thanks for your help.

0 Kudos
Highlighted
Employee
7 Views

Hi

We are following up on your post and we would like to know if you still need help or if you already have an answer or solution to your question. Remember if someone replied to you with a helpful response you can mark it as correct or helpful answered. We will be waiting your response. Have a great day.

 

Regards,

Sergio

Highlighted
New Contributor II
7 Views

Hello All,

I am using Adafruit_ILI9341 and Adafruit_STMPE610 libraries with my Galileo Gen1 board for display and touch with Adafruit 2.8" TFT screen.

I am using SPI communication but I find that the screen responds too slow. Does anyone have an idea on how I can improve the speed of SPI communication ?

Thanks

--Paridhi

0 Kudos
Highlighted
Employee
7 Views

Hi Paridhi_Agrawal,

Have you tried modifying the SPI.cpp as we suggested above? We tried this and we accomplished 25MHz but I'm not sure if this modifies something else. But maybe you can try using this speed instead of the standard.

Regards,

 

JPMontero_Intel
0 Kudos