Microchip
直播中

柳杨

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

没有收到有关I2C总线的任何数据

我使用DS1307 RTC获取时间,但是当我开始从从属设备主设备接收数据时,请挂起。

以上来自于百度翻译


      以下为原文

    I am using DS1307  RTC to get time but when I start receiving data from slave device master device get hang in

I2C2CONbits.RCEN = 1; //set I2C module to receive
while(I2C2CONbits.RCEN==1);

while (I2C2STATbits.RBF==0) //wait for response
{ Nop(); }

I2C2STATbits.I2COV = 0;

data = I2C2RCV;

I2C2CONbits.ACKDT = ack;
I2C2CONbits.ACKEN = 1;
while(I2C2CONbits.ACKEN == 1);
    I2C_stop();
return data; //return data

回帖(18)

李铭鑫

2019-3-6 12:47:47
如果出现了错误,消息“1”中的代码将挂起(I2C2STATBITS.RBF=0);如果前面的语句:I2C2CONBITS.RCEN返回到0,则没有接收到字节,那么等待RBF将无济于事。迈西尔

以上来自于百度翻译


      以下为原文

    If there is something wrong, code shown in message #1 will hang in the
    while ( I2C2STATbits.RBF == 0); 
loop.
If a byte have not been received when the previous statement:     I2C2CONbits.RCEN    go back to 0,
then waiting for RBF will not help.

    if (I2C2STATbits.RBF == 0) //check for response
    {   __debug_break();

                    // test what went wrong

                    // what is value of I2C2STATbits.BCL

                    // what is value of I2C2STATbits.IWCOL

                    // what other values in I2C2STAT

        if (I2C2STATbits.S == 1)

            I2C_stop();

        return error;

    }  

 
   Mysil
举报

徐依妮

2019-3-6 12:59:14
如何在C30编译程序中写入上面的位是错误的。i2cIt.h:82:错误:“I2C2STATBITS”没有名为“RW”的成员。

以上来自于百度翻译


      以下为原文

    I2C2STATbits.RW
 
how to write above bit in C30 compiler
I am getting error.
 
I2C_int.h:82: error: 'I2C2STATBITS' has no member named 'RW' 
举报

李铭鑫

2019-3-6 13:17:34
您好,您可以尝试:I2C2STATBITS.RY-WOR I2C2STATBITS。RYNOTHOWWW,但是该位是由硬件设置和清除的只读状态位,因此在那里写入东西可能没有效果。迈西尔

以上来自于百度翻译


      以下为原文

    Hi,
You may try:
    I2C2STATbits.R_W   
or
    I2C2STATbits.R_NOT_W
but that bit is a Read-only status bit that is set and cleared by hardware, so writing something there will likely have no effect.
 
   Mysil
举报

徐依妮

2019-3-6 13:27:27
我使用的是20MHz的外部晶体,什么值应该用II2C2BRG得到100kHz的时钟速率。

以上来自于百度翻译


      以下为原文

    I am using 20Mhz external crystal what value should be use in I2C2BRG to get 100KHz clock rate. 
举报

更多回帖

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