SPI shift_in and shift_out are slow in Propeller C on a Propeller1
I am using a FLIP module (propellor1) and the PropellerC "shift_in" and "shift_out" functions to communicate with a MCP3008 ADC chip. The code first sends a 5-bit command to the MCP3008 to sample via "shift_out" then immediately uses "shift_in" to receive an 11-bit result (the chip sends a null as the 1st data bit). This process takes about 1.24 msec to complete resulting a maximum sampling rate of about 800 Hz. This is surprisingly slow for a MCP3008 that has a specification of 75 kips at 2.7v supply. Does anyone know how to speed up SPI communication on the propeller? The interface on the propeller is 100 time slower than the chip specification. Is this expected? The code looks like ...
int mcp3008_read(char c)
int i; // 32 bit Propeller integer and float have 32 bits
i = 0x18 | c; // Assembles ADC input command
low(mcpCS); // mcpCS set low to select ADC
// shift_out with MSBPOST stands for most significant bit first & data valid after pulse
shift_out(mcpDIN, mcpCLK, MSBPOST, 5, i); //Sends "i" as "1,1,x,x,x"
// so each bit is read when clock level goes high to low, "null" bit plus 10 data bits
i = shift_in(mcpDOUT, mcpCLK, MSBPOST, 11); // get ADC result in MSBPOST format
high(mcpCS); // Deselects ADC
return i; // Returns ADC count value
Data Signal (2) reads “00111101000” = 48810 = 1569mv @ vref = 3290mv and agrees with my voltmeter.