Faster SPI in C (GCC), how?
mh3soldier
Posts: 3
Hello,
Is there a way to specify the frequency for the functions?:
shift_out(7, 8, MSBFIRST, 7, 0b1010110);
shift_in(7, 8, MSBPRE, 8);
Using those two functions will start a COG, right? So there should be a way to specify the frequency, am I right?
Thanks in advance.
Is there a way to specify the frequency for the functions?:
shift_out(7, 8, MSBFIRST, 7, 0b1010110);
shift_in(7, 8, MSBPRE, 8);
Using those two functions will start a COG, right? So there should be a way to specify the frequency, am I right?
Thanks in advance.
Comments
Do you want faster or slower? Either way, you can't change the speeds of these functions. They send as fast as they can, which is pretty slow because they use many higher-level functions instead of directly manipulating OUTA, INA, and DIRA. I wrote my own significantly faster one (and it's still sad how slow it is), but I don't have it on this computer and it didn't support all of the different modes - only the ones I needed (but it's pretty easy to change it). There might be other functions in simpletools that you can configure, but I doubt it. Unless you can find someone else's library that's faster than simpletools', your best bet is probably writing your own. If you need somewhere to start, there's a SPI_Spin.spin in the Spin library that comes with the Propeller Tool that you might be able to port to C.
Here's the link to the Spin SPI library: http://obex.parallax.com/object/566. It says it's for a temperature sensor, but that's just the demo. You just want the SPI_Spin.spin in the zip file. It should be pretty easy to port to C. If you've never seen any Spin before, note that it uses indentation for blocks instead of curly brackets.
Here's the class documentation:
http://david.zemon.name/PropWare/classPropWare_1_1SPI.xhtml
Note: shift_*_fast and shift_*_sector are planned methods that have not yet been implemented (I think shift_*_fast just calls the normal shift_* assembly at the moment), but these are the methods that will be capable of achieving 4 MHz.
David
[/FONT]