I'm trying to have a go at writing a .cpp and .h file for a 16bit dac (using 24 bit word over spi) the first problem is I need to make three choices in the first bite of data there's 1 bit for read/write a non functioning 0 then 3 bits for choice of mode then another 3 bits for dac channel.
I can just place all 3 setts of data in the correct place of the bite by making them all into 8 bits and bit masking them with an OR | statement as the zeros would only be replaced by ones as they would want to be but I'm not shore how to make the choices of the three bits that I want
void dac::ReWr(bit db23, bit db22)//dac readWrite db23 - db22
{
for ReWr.write(0, 0, 0, 0, 0, 0, 0, 0);//00 write 0B
for ReWr.read(1, 0, 0, 0, 0, 0, 0, 0);//10 read
}
void dac::regi(bit db21, bit db20, bit db19) //dac function db21 - db19
{
for regi.function(0, 0, 0, 0, 0, 0, 0, 0); //000 function register
for regi.data(0, 0, 0, 1, 0, 0, 0, 0); //010 data register + dac + db15 - db0
for regi.coarse(0, 0, 0, 1, 1, 0, 0, 0); //011 coarse gain register + dac + dontcare + db1 - db0
for regi.fine(0, 0, 1, 0, 0, 0, 0, 0); //100 fine gain register + dac + dontcare + db5 - db0
for regi.offset(0, 0, 1, 0, 1, 0, 0, 0); //101 offset register + dac + dontcare + db7 - db0
}
void dac::channel(bit db18, bit db17, bit db16) //dac channel db18 - db16
{
for channel.chanA digitalWrite(0, 0, 0, 0, 0, 0, 0, 0);//000 dac a
for channel.chanB digitalWrite(0, 0, 0, 0, 0, 0, 0, 1);//001 dac b
for channel.chanC digitalWrite(0, 0, 0, 0, 0, 0, 1, 0);//010 dac c
for channel.chanD digitalWrite(0, 0, 0, 0, 0, 0, 1, 1);//011 dac d
for channel.chanAll digitalWrite(0, 0, 0, 0, 0, 1, 0, 0);//100 dac all dac's
}
//use bitwise with "or |" to put the 1's in the right place of the bite "0,0,0,0,0,0,0,0" this adds the weri+regi+channel