HC12 IIC - Need help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC12 IIC - Need help

1,669 Views
chuckles
Contributor I
I need some pointers/help in using IIC bus.
 
I'm using it to send data to a serial DAC (Max521), which is compatible with IIC. However, when I run my code I'm not convinced that it is outputting the correct wave forms...
 
The code is something like this:
 for(;:smileywink: {
 init_IIC();
 write_IIC();
 } 
 

void init_IIC(){
 //Try Setting DDRJ
 DDRJ_DDRJ6=1;
 DDRJ_DDRJ7=1; 
  
 IBFD = 0x20;  //Frequency divider
 IBAD = 0x1F;  //This is to set the slave address of the IIC  -- Doesn't really matter ?
 IBCR= 0xB0; //Enables, makes master, sets to transmit
  }
 
 
void write_IIC() {
 IBDR = 0x50; // Slave Address 0101 0000
 
 while(IBSR_TCF ==0 ) {
   asm(nop);
 }
 
 IBDR= 0x00; //DAC0
 
 while(IBSR_TCF ==0 ) {
   asm(nop);
 }
 
 IBDR = 0xFF;//Activate DAC full tilt
   
 while(IBSR_TCF ==0 ) {
   asm(nop);
 }
 
 IBCR = 0; //Stop Transmission.
}
 
 
 
Any Suggestions would be greatly appreciated. Thanks guys.
 
Labels (1)
0 Kudos
1 Reply

402 Views
erooll
Contributor II
Try change your code for this

void write_IIC() {
 IBDR = 0x50; // Slave Address 0101 0000

//wait until transfer all byte
 while(!IBSR_IBIF);

 //clear flag
 IBSR_IBIF = 1;

    //Check ACK
     if(IBSR_RXACK)      //if this bit its set, the device not response
       _asm nop;           //include here something
    else
       _asm nop;         //All OK, your DAC response to Address call
 }
0 Kudos