Other Parts Discussed in Thread: DAC8871
I'm using the SPI to communicate with the DAC8871. If I write to the SPITXBUF register it looses the MSB and therefore I can only count to 32767 instead of 65535. I have a global variable, volatile unsigned int DAC_value, and a function, DAC_update(void), that sends the value over the SPI. By using the global variable I loose the MSB. If I make a temp variable inside DAC_update(void) and send that, just to test it, it works fine.
Code:
void DAC_update(void)
{
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG != 0);
SpiaRegs.SPITXBUF = (unsigned int) DAC_value;
}
inside an timer interrupt:
if(DAC_value > 65000)
DAC_value = 0;
else
DAC_value += 10;
DAC_update();
If I change the update function to that below it send the full value and the DAC outputs the maximum value.
void DAC_update(void)
{
unsigned int data = 65535;
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG != 0);
SpiaRegs.SPITXBUF = data;
}