Microchip
直播中

段宜敏

7年用户 236经验值
私信 关注
[问答]

PIC18LF24K40芯片编写I2C程序时在SCL和SDA线上得到了一个很高的波形

您好,我在PIC18LF24K40芯片上工作,在编写I2C程序时遇到了问题,尽管遵循了数据表中的指令,但是我在SCL和SDA线上得到了一个很高的波形,而不是像预期的波形。PS:我对PIC是新的,但是对AVR芯片有一定的经验。因此,我不是一个完整的初学者。

以上来自于百度翻译


      以下为原文

    Hello,
Im working with PIC18LF24K40 chip and i have a problem while writing 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.

回帖(4)

蒋喜玲

2019-2-14 14:46:08
对于SCK和SDA,需要输入和输出PPS都配置相同。RC3 PPS输入默认为CLK,RC4默认为SDA。您已经将输出设置为相反。您应该明确地设置输入,而不是依赖默认值。

以上来自于百度翻译


      以下为原文

    For SCK and SDA you need to have both input and output PPS configured the same. RC3 PPS input defaults to CLK, and RC4 defaults to SDA. You have set the outputs to opposite.
 
You should probably explicitly set the inputs, rather than rely on defaults.
举报

李衍安

2019-2-14 14:58:23
谢谢,这是我的错误,用相反的值填写这些寄存器。所以现在我把I2CII初始化例程改成了下面的内容。

以上来自于百度翻译


      以下为原文

    Thank you it was my mistake to fill those registers with the opposite values.
So now i changed the I2C_initialize routine to the following.
 

void I2C_Inititalise()
{
    RC3PPS         = 0x0D; //PPS OUTPUT CLK  
    RC4PPS         = 0x0E; //PPS OUTPUT SDA
    
    SSP1CLKPPS     = 0x13; //PPS INPUT CLK
    SSP1DATPPS     = 0x14; //PPS INPUT SDA
    
    SSP1CON1       = 0x28;  //I2C Mode
    SSP1CON2       = 0x00;
    SSP1STAT       = 0x00;   
    SSP1ADD        = 0x04;
}
 

 
It still does not seem to make a difference on the SCL and SDA lines.
举报

李衍安

2019-2-14 15:07:36
现在它工作了,我必须明确地清除相关的信息。在配置UJART模块的TJHE接收中断时,我偶然发现了它。通过添加这个,我可以看到总线上的CLLCK和数据。令人惊叹的。非常感谢你的帮助!

以上来自于百度翻译


      以下为原文

    Its working now, I had to explicitly clear the relevant ANSELCbits. I discovered it by accident while configuring tjhe receive interrupt for USART module.
 
By adding this i can see cloclk and data on the bus. Awesome. :)

    ANSELCbits.ANSELC3 =0;
    ANSELCbits.ANSELC4 =0;

 
Thanks so much for your help!
举报

蒋喜玲

2019-2-14 15:18:57
好工作。

以上来自于百度翻译


      以下为原文

    Good work.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分