SPI bit adressing question
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:
'set the right Prop pins as outputs dira[CSPin] := 1 dira[MOSIPin] := 1 dira[SCLKPin] := 1 'Set bits 16 to 23 to zero (command to turn on/off) 'Set the "switch" bits to enable the first 8, disable the next 8 outputs value := (0<<16) | ($00FF) outa[CSPin] := 0 'enable data transfer to the chip by setting chip select pin low repeat bit from 0 to 23 'set the bit to output outa[MOSIPin] := (value >> (23-bit)) & 1 'toggle the clock pin outa[SCLKPin] := 1 outa[SCLKPin] := 0 outa[CSPin] := 1 'apply the register change you just sent by setting CS highThat'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 ~