2007-08-14 09:22 PM
2007-08-14 09:22 PM
hello everybody
i have a question about i2c(m24c01) application i send 24 byte data to eeprom with i2c. i can send first 8 byte to eeprom. after that i try to send second byte but i2c hasn't writen i generate wait function with for loop.i add wait function between write(00) and write(08) codes. it's allright. but i want to do this without wait function . namely i want to polling. already thanks for help void main(void) { . . . i2ctemp[0]=0x23; i2ctemp[1]=0x23; i2ctemp[2]=0x24; i2ctemp[3]=0x24; i2ctemp[4]=0x28; i2ctemp[5]=0x25; i2ctemp[6]=0x30; i2ctemp[7]=0x26; write(00); write(08); } void write(Byte address) { I2cTxBytes[1]=i2ctemp[0]; I2cTxBytes[2]=i2ctemp[1]; I2cTxBytes[3]=i2ctemp[2]; I2cTxBytes[4]=i2ctemp[3]; I2cTxBytes[5]=i2ctemp[4]; I2cTxBytes[6]=i2ctemp[5]; I2cTxBytes[7]=i2ctemp[6]; I2cTxBytes[8]=i2ctemp[7]; PBDR=0x66; WriteEeprom(adres); PBDR=0x77; } void WriteEeprom(unsigned char address)//,unsigned char data) { I2cTxBytes[0]=address; I2cTxPtr=&I2cTxBytes[0]; I2cTxEndPtr=&I2cTxBytes[(Txpacketsize-1)]; I2cMode=1; //TX,mode master sends data to slave I2c_Status=0; GenerateStart(); PBDR=0x80; while(!I2c_Status); PBDR=0X84; } void I2C_It_Func(void) { unsigned char Temp; Temp=I2CSR1; if(Temp == (EVF|BUSY|MS_SL)) //EV6 { I2CCR|=PE; Temp = I2CSR1; } if(I2CSR2&AF) { PADR=0xFF; } if(I2cMode==1) //Transmit data to eeprom { if(Temp & SB) { I2CDR=SlaveAdr; //SlaveAdr=0xA6 } else if(Temp&BTF) { if(Temp&TRA) { if(I2cTxPtr==(I2cTxEndPtr+1)) { I2c_Status=1; GenerateStop(); } else { I2CDR=*I2cTxPtr; I2cTxPtr++; } } } } if(I2cMode==2) //Recieve data to eeprom { if(Temp & SB) { if(RepStart==0) { I2CDR=SlaveAdr; } else { I2CDR=(SlaveAdr|0x01); RepStart=0; } } else if(Temp&BTF) { if(Temp&TRA) { if(RepStart==1) { GenerateStart(); } else { I2CDR=*I2cTxPtr; RepStart=1; //Repeated Start signal will be generated. } } else { if(!(I2cRxPtr==I2cRxEndPtr)) { if(I2cRxPtr==(I2cRxEndPtr-1)) { I2CCR&=~ACK; *I2cRxPtr=I2CDR; GenerateStop(); I2cRxPtr++; } else { *I2cRxPtr=I2CDR; I2cRxPtr++; //RepStart=0; } } else { *I2cRxPtr=I2CDR; I2c_Status=1; } } } } }