SPI bit adressing question
jdolecki
Posts: 726
I'm trying to learn how to control the individual bits in the 24 bit stream.
I am using this chip
http://cache.nxp.com/files/analog/doc/data_sheet/MC33996.pdf?pspll=1
Basically is and 16 output on/off switch controlled by SPI.
So my question is how do in configure the output message to control The individual bits to turn them on and off?
Hope i explained that correctly.
Thanks John
I am using this chip
http://cache.nxp.com/files/analog/doc/data_sheet/MC33996.pdf?pspll=1
Basically is and 16 output on/off switch controlled by SPI.
So my question is how do in configure the output message to control The individual bits to turn them on and off?
Hope i explained that correctly.
Thanks John
Comments
The longer answer is that you'll need to build up the 24 bit value as either 3 bytes, or a single 32 bit value, then send it to the device via SPI. Doing that means setting the "Chip Select" line to the device, then for each bit, you set the MOSI pin to the bit you're sending, then toggle the SCLK pin to tell the device to read the bit. According to the spec you send the most significant bit (bit 23) first, and the least significant bit (bit 0) last. The code would look something like this:
That's the rough idea - I have no idea if this will compile, but it should get you started.
(edited to correct syntax for bitwise NOT operation in Spin)
BTW, the Spin operator to use to clear the bits involves a NOT operation before ANDing, so that is actually a ! and not a ~