bassplayer142
Newbie level 5
I am trying to connect this digital to analog converter to the micro-controller with a small issue. First off, I the MCP4922 has 2 seperate 12 bit channels and the first one I send data to works while the other way stays near 0 volts. I have played with the CKE and CKP values which change whether the clock is active low or high and where on the clock pulse but I can't get the second one to register. I find it strange because if I put a msdelay between sending the first d-2-a (temp1 and temp2) then both don't work. I'm near positive that this is just some kind of timing issue. Any help is appreciated greatly and thanks in advance.
**broken link removed**
**broken link removed**
Code:
void initspi(void){ //initialize spi interface
SPI1STAT = 0x0000;
SPI1CON = 0x0038;
SPI1CONbits.CKE = 0; //top or bottom clock
SPI1CONbits.CKP = 0;
SPI1CONbits.SMP = 0;
SPI1STATbits.SPIEN = 1; //enable
CSDAC = 1;
LDAC = 1;
msdelay(10);
}
void updatedac(unsigned int fir, unsigned int sec){
unsigned char temp1,temp2,temp3,temp4 = 0;
temp1 = (fir >> 8)&0x0F;
temp1 = 0x30 | temp1;
temp2 = (char)fir;
temp3 = (sec >> 8)&0x0F;
temp3 = 0xB0 | temp3;
temp4 = (char)sec;
CSDAC = 0;
sendspi(temp1);
sendspi(temp2);
CSDAC = 1;
CSDAC = 0;
sendspi(temp3);
sendspi(temp4);
CSDAC = 1;
LDAC = 0;
LDAC = 1;
}
void main(void){
initspi();
TRISF = 0x00;
msdelay(10);
k2 = 2000;
while(1){
k+= 10;
k2+=10;
updatedac(k,k2);
if (k > 4095) k = 0;
if (k2 > 4095) k2 = 0;
}
}