Ranjitharanju
Newbie level 4
- Joined
- Feb 12, 2014
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 72
Hi I m trying to interface I2c with DAC(IC-MAx5215(slave device)) in pic24f(master device) but I am not getting the output. Even i am not getting what mistake i m doing please anyone can help me I am using system clock 32Mhz.
here is my code
Thank you.
here is my code
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 #include<p24fj128ga010.h> #define FCY 16000000 _CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) _CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL) #define bUs__idLe 0x8000 #define i2c_disable 0x0000 #define I2c_____conTroL I2C1CON void I2C_WRITE(char Mdata,char Ldata); void start(void) { I2C1CONbits.SEN = 1; //Start Condition Enable bit while(I2C1CONbits.SEN); // I2C start bit verification } void stop(void) { I2C1CONbits.PEN = 1; //Stop Condition Enable bit while(I2C1CONbits.PEN); // I2C start bit verification } void rpt_start(void) { I2C1CONbits.RSEN = 1; //Restart Condition Enable bit } void write(char data) { I2C1TRN = data; } int main(void) { while(!OSCCONbits.LOCK ); //CLOCK FREQUENCY 32MHz I2C_INIT(); while(1) { I2C_WRITE(0xFF,0xFF); } return 0; } void I2C_INIT(void) { /* I2C1CONbits.I2CSIDL = 1; // STOP IN IDEL MODE I2C1CONbits.SCLREL = 0; //SCL RELESE CONTROL BIT I2C1CONbits.A10M = 0; //SLAVE ADDRESS BIT SELECT PIN I2C1CONbits.DISSLW = 1; //SLEW RATE DISABLE BIT I2C1CONbits.SMEN = 0; //SMBUS INPUT LEVEL BIT // BIT 8 I2C1STATbits.I2COV = 1; //Receive Overflow Flag bit */ I2c_____conTroL = 0x8000; I2C1STAT = 0x0030; //status bit register I2C1MSK = 0X0000; //MASK REGISTER I2C1BRG = 0x4f; //BAUD RATE SETTING } void I2C_WRITE(char Mdata,char Ldata) { I2c_____conTroL = i2c_disable; __delay32(100); I2c_____conTroL = bUs__idLe ; __delay32(100); start(); write(0X38)); //slave device address while(I2C1STATbits.TBF); //waiting for complete transmission while(!IFS1bits.MI2C1IF); while(I2C1STATbits.ACKSTAT); //waiting for slave ack write(0X02); //user command address while(I2C1STATbits.TBF); while(!IFS1bits.MI2C1IF); while(I2C1STATbits.ACKSTAT); write(Mdata); while(I2C1STATbits.TBF); while(!IFS1bits.MI2C1IF); while(I2C1STATbits.ACKSTAT); write(Ldata); while(I2C1STATbits.TBF); while(!IFS1bits.MI2C1IF); while(I2C1STATbits.ACKSTAT); stop(); __delay32(100); I2c_____conTroL = bUs__idLe ; __delay32(100); I2c_____conTroL = i2c_disable; __delay32(200); } void __attribute__ ((__interrupt__,no_auto_psv)) _MI2C1Interrupt(void) { // IFS1bits.MI2C1IF = 0; }
Thank you.
Last edited by a moderator: