1
\$\begingroup\$

I'm trying to read data from a RGB sensor (S9706) and I thought about using the SPI for the readings.

The problem is that the sensor wants a little pause of 3-4us after each 12-bits (the colors resolution is 12-bit) I read, and the hardware SPI can read 7 or 8 bits at once. So if I choose to read 7-bits each time, I will not be able to make the pause after 12-bits, and I might loose some data while reading 2 more bits than I should.

S9706 Timing chart

Is there a way to read exactly 12-bits (12 clock pulses only) with the SPI, or should I write a bit-bangging function to do what I want?

Thanks!

EDIT

Eventually, I choose to do it with bit banging, although I think it might be possible to use SPI with low a frequency of 200Khz. With 200Khz every clock will be 10us, 50% dc = 5us, and it's more than the pause I need after every 12 bits.

what I don't sure is what will happen between bit 37 to 40, because the SPI will read 5 bytes (40 bits) and the sensor has data for 36 bits. It might start sending new data from the next 36 bits..

\$\endgroup\$
6
  • \$\begingroup\$ You can't transmit only 12-bits over SPI. Has to be bytes. Since you only need one way communication, bit banging seems easiest. \$\endgroup\$ Commented Jul 7, 2015 at 11:58
  • \$\begingroup\$ @Josiah Hester Thank you. that's what I did eventually \$\endgroup\$ Commented Jul 7, 2015 at 11:59
  • \$\begingroup\$ Actually, there are microcontrollers out there that support a variable transfer length of 8 to 16 bits. See for example NXP's LPC21xx series. So stating that SPI is always a multiple of 8 bits/byte-wise is misleading at best. \$\endgroup\$ Commented Jul 7, 2015 at 12:27
  • \$\begingroup\$ @FRob you are right, since SPI is not formally standardized that is the case. But 8-bit SPI is common on MSP430 devices, that was what I meant. \$\endgroup\$ Commented Jul 8, 2015 at 1:49
  • \$\begingroup\$ On this specific family it can be either 7 or 8. \$\endgroup\$ Commented Jul 17, 2015 at 14:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.