发 帖  
原厂入驻New
实战多通道高速精密测温仪的全系列设计教程,以实际项目为依托,提升工程师核心竞争力!→点击立即抢购←
[问答] 使用pic18f4520的I2c通信出现问题
112 I2C 传感器
分享
他使用pic18f4520与德州仪器LDC1612感应传感器通信,当我试图从LDC1612读取数据时,读取它的总是0x7FFF。感谢您的帮助。这里是ldc1612和pic18f4520数据表ldc1612和pic18f4520数据表www.ti.com/" target="_blank">http://www.ti.com.com.[url]www.ti.com/[/url]光亮/ds/snoscy9/snoscy9.snoscy9/snoscy9/snoscy9.pd9.pdf//http://http://www1.微芯片.com/...n/DeviceDoc/39631E.pdffff以下是我正在使用的代码。\\\\\\\\\\\\\\\\\\\\\\SC=0b10011011;PORTCbits.RC5 = 0;CloseI2C();OpenI2C (MASTER, SLEW_OFF);SSPADD = 9;Starti2C();while(SSPCON2bits.SEN);IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x08);IdleI2C();AckI2C();IdleI2C();WriteI2C(0xFF);IdleI2C();AckI2C();IdleI2C();WriteI2C(0xFF);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x10);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x04);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x00);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x14);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x10);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x01);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x19);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x00);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x85);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x1A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0X1E);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x01);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x1B);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x02);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x0c);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x1e);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x84);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x40);IdleI2C();NotAckI2C();IdleI2C();StopI2C();StartI2C();IdleI2C();WriteI2C(0X2A);IdleI2C();AckI2C();IdleI2C();WriteI2C(0x7E);IdleI2C();NotAckI2C();IdleI2C();StopI2C();PORTCbits.RC5=1;StartI2C();IdleI2C();WriteI2C(0X2B);IdleI2C();AckI2C();IdleI2C();DataRdyI2C();IdleI2C();RawDataHi = REdi2c-();AcII2C~();IDLeI2C~();RawDataLo=Redi2C~();IDLeI2C~();NoTaCi2C~();Studii2C~();而(1);};

以上来自于百度翻译


      以下为原文

    Hi

im using pic18f4520 to communicate with texas instrument LDC1612 inductive sensor, when i try to read data from the LDC1612 the reading its always 0x7FFF. Any help is appreciated thank you in advance. Here is the link for ldc1612 and  pic18f4520 datasheet http://www.ti.com/lit/ds/snoscy9/snoscy9.pdf // http://ww1.microchip.com/...n/DeviceDoc/39631E.pdf


below is the code that i am using.


#include <p18f4520.h>
#include <i2c.h>

char RawDataHi=0, RawDataLo=0;
void main ()
{

TRISC = 0b10011011;
PORTCbits.RC5 = 0;
CloseI2C();
OpenI2C (MASTER, SLEW_OFF);
SSPADD = 9;
StartI2C();
while(SSPCON2bits.SEN);
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x08);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0xFF);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0xFF);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x10);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x04);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x00);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x14);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x10);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x01);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x19);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x00);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x85);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x1A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0X1E);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x01);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x1B);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x02);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x0c);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x1e);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x84);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x40);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

StartI2C();
IdleI2C();
WriteI2C(0X2A);
IdleI2C();
AckI2C();
IdleI2C();
WriteI2C(0x7E);
IdleI2C();
NotAckI2C();
IdleI2C();
StopI2C();

PORTCbits.RC5=1;
StartI2C();
IdleI2C();
WriteI2C(0X2B);
IdleI2C();
AckI2C();
IdleI2C();
DataRdyI2C();
IdleI2C();
RawDataHi = ReadI2C();
IdleI2C();
AckI2C();
IdleI2C();
RawDataLo = ReadI2C();
IdleI2C();
NotAckI2C();
StopI2C();
while(1);
}
0
2019-7-17 13:15:26   评论 分享淘帖 邀请回答
1个回答
你好,请对你的代码做一些评论。然后我们可以看到你想要做什么。

以上来自于百度翻译


      以下为原文

    Hi,
 
Please put some comments on your code. Then we can see what you are trying to do.
 
 
2019-7-17 13:27:04 评论

举报

只有小组成员才能发言,加入小组>>

44个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /10 下一条

快速回复 返回顶部 返回列表