完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
他使用pic18f4520与德州仪器LDC1612感应传感器通信,当我试图从LDC1612读取数据时,读取它的总是0x7FFF。感谢您的帮助。这里是ldc1612和pic18f4520数据表ldc1612和pic18f4520数据表www.ti.com/" target="_blank">***[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 #include 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); } |
|
相关推荐
1个回答
|
|
你好,请对你的代码做一些评论。然后我们可以看到你想要做什么。
以上来自于百度翻译 以下为原文 Hi, Please put some comments on your code. Then we can see what you are trying to do. |
|
|
|
只有小组成员才能发言,加入小组>>
5170 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
508浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
634浏览 0评论
531浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 14:49 , Processed in 1.124287 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号