Hi Mike,
I have been using your bcm2835 C library on my Raspberry Pi to control the SPI bus. It’s awesome! Very easy to use! But I’m monitoring the bus with an oscilloscope, and finding a limitation that I’d like to ask you about.
I’m using it to read data from the MCP3008 A/D converter that Adafruit.com sells. I’m sending and reading 3 bytes at a time using bcm2835_spi_transfernb(), for each sample, the way the spec sheet for MCP3008 describes. I’m reading the data just fine, but there seems to be a limitation as to how often I can read a sample, no matter how fast I set the SPI bus to. (It takes 3 bytes to read one sample.)
If I monitor the chip select and the clock using a ‘scope, I see chip select go low, 8 clocks, a gap, 8 more clocks, another gap, 8 more clocks, a gap, and then chip select goes high briefly until the next sample, at which point the pattern repeats. So far that sounds normal, right? But if I increase the SPI bus speed, I see each group of 8 clocks gets narrower as expected, but the gap gets larger before the next 8 clocks come out, causing each chip select to happen at the exact same interval as before! This prevents me from sampling faster than about 28KHz. Whether I use a clock divider of 24 or 300… I get the exact same interval between chip selects. Once I go above a divider of ~300, there isn’t enough room for the 3 sets of 8 clocks between each chip select, so then the chip selects start getting farther apart, allowing a slower sample rate. But I want to go faster than 28KHz, and there appears to be plenty of time to do so, but it seems that your library is waiting a constant amount of time after sending the first clock of the first byte before it sends the first clock of the 2nd byte, (and again with the 3rd byte) preventing me from increasing the sample rate above 28KHz.
Is there any way around this?
I’m not doing much in my code between samples, chip select is only going high for about 640ns, so it’s not that I have a ton of code between each sample slowing things down.
Any advice would be appreciated.
Regards,
Ken