您好,我在PIC18LF24K40芯片上工作,在编写I2C程序时遇到了问题,尽管遵循了数据表中的指令,但是我在SCL和SDA线上得到了一个很高的波形,而不是像预期的波形。PS:我对PIC是新的,但是对AVR芯片有一定的经验。因此,我不是一个完整的初学者。
以上来自于百度翻译
以下为原文
Hello,
Im working with PIC18LF24K40 chip and i have a problem while wri
ting an I2C program, in spite of following the instructions in Datasheet, i get a HIGH on SCL and SDA lines instead of a Waveform as expected.
void I2C_Inititalise()
{
RC3PPS = 0x0E;
RC4PPS = 0x0D;
SSP1CON1 = 0x28; //I2C Mode
SSP1CON2 = 0x00;
SSP1STAT = 0x00;
SSP1ADD = 0x04; // Clock 400KHz
}
void send_start()
{
while(SSP1STATbits.RW); // wait for write to complete
SSP1CON2bits.SEN=1; //set start enable bit
if(PIR3bits.BCLIF==1)
PIR3bits.BCLIF =0; //Clear collision bit in PIR register
while(SSP1CON2bits.SEN); //waits to get cleared by hardware
}
void main(void) {
TRISCbits.TRISC2=0;
init_oscillator();
I2C_Inititalise();
while(check_for_bus_free_iic());
send_start();
write_to_bus(0x2A<<1); //Address of slave + bit 0 (W)
while(1){
LATCbits.LATC2 ^= 1;
PORTCbits.RC2 ^= 1;
}
return;
}
PS: I am new to PIC but have some experience with AVR chips. Therefore im not a complete beginner.