[SOLVED] Arduino SPI with non standard number of bits (NON 8bit clock)

Hi,

I have an SPI peripheral that requires an unusual number of bytes clocked in (25) which is annoying that it won't divide by 8..

As far as I can tell, I can't find a way to interrupt the spi_transfer function part way through clocking out, it will just churn through those 8bits! Another part of the problem is it is on same bus as another SPI device that DOES divide by 8 (reasons why this is a problem further on):

  1. Bit banging - I have bit banged the 25bits and performance is good, however when using the Arduino SPI library I have to call SPI.end() and then SPI.begin() after I'm done (this takes 20uS to init)

  2. SPI HW for 24bits and 1x bit banged bit - Again similar problem to #1; just doing a digitialWrite to the SPI pins doesn't seem to work? It seems to write the pin before SPI has completed messing it up (non blocking?). This would be the ideal solution as i just need to clock in a 0 at the end

  3. Using my own spi_transfer function (copied with blocking) - seems to be the best so far, although I have to also write an init function too..

Any thoughts? Ideally a better way of using the AVR settings (in spi_transfer)

EDIT Solved by clocking in extra zeros at the start (which will get shifted out at the end)

What device are you talking to? Most devices just keep clocking bits through until you tell them the transfer is over. It doesn't really count bits, it just keeps the last 25 that it was sent. In that case, just send four bytes and the first seven bits of the first byte won't matter. The last bit of the first byte should be the first bit you want to send.

Hmm good point! I'll give that ago tomorrow

Datasheet says the data is stored in a shift register until CE rising edge so by the sounds of it will just shift it out and when I lift CE it will use the buffer! 7x leading 0's should do the trick :)

Thanks for the insight

Worked perfectly! Thanks