完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我的第一篇文章,SOAPPACtiON。问题陈述:在I2C上的SDA线在一个随机周期之后变低,并且保持低直到POR。I2C直到SDA保持低工作良好。M22通过250mm的引线连接到PIC。有没有办法在不做POR的情况下重置线路?HypSpRealAlxIIII2C函数=2C1BRG=39;TribbTe.TrISB9=1;/SDA TrbBITS.TrISB8=1;//SCL OSCCon=0x000;//CKDIV= 0x0700;ReCopon=0x000;//此函数将初始化I2C(1)外围设备。/现在我们将初始化I2C外围设备为主模式,没有转换速率/控制,让外围设备关掉。I2C1CONC= 0x1200;I2C1RCV= 0xMUN;I2C1Trn=0x000;现在/我们现在可以启用外围I2C1CONC= 0x9200;//I2CEN,SCLREL,DISSLWNONDENT STARTI2C(空隙){//此函数生成I2C启动条件,返回START.I2C1CONBITS.See=1的状态/ /;/生成启动条件WHILE(I2C1CONBESS.SEN);/ /等待开始条件返回(I2C1STATBITS。);/ /可选地返回状态}未签名int Studi2C(空隙){//此函数生成I2C停止条件,并返回STAT//STEP。I2C1CONBITS.PIN= 1;/ /生成停止条件(I2C1CONTITES。PEN);/ /等待STOP返回(I2C1StATBATS.P);//可选-返回状态}未签名int WrIeI2CyBuffor(无符号char字节){///此函数将传递给函数//In的字节(I2C1STATBITS.TrSTAT)发送;/ /等待总线空闲I2C1Trn=字节;//加载字节到I2C1传输缓冲器(I2C1STATBIT.T)BF);/ /等待数据传输返回0;}无符号int IDLIE2C(空隙){(I2C1STATBITS.TrSTAT);/ /等待总线空闲返回0;}无符号int Wrave2C(无符号char控制字节,无符号char Load,未签名CHAR数据,未签名CHAR CNT){un签署int错误代码;IDLeI2C.());/ /确保模块是空闲STARTI2c();//生成起始条件WreIe2CyBuffor(控件字节);//写入控制字节IDLeI2C~();ErrOrCord= ACKStaseUE(;)//ACK ACSTATUSTORIGII2CYBULL(LoLADD);//编写低地址IDLeI2C~();ErrOrCord= ACKSTATUSER(;)//ACK ACK STATUS WORIII2CY缓冲器(数据);//写入数据IDLII2C~();Studii2C~();//启动停止条件返回(ErrOr码);}
以上来自于百度翻译 以下为原文 Hello Everybody, My first post, so apologies in advance. Problem Statement: SDA line on I2C goes low after a random period, and stays low until a POR. I2C up until the the SDA staying low works fine. The MD22 is connected to the PIC via 250mm leads. Is there a way to reset the lines without doing a POR? Thanks Paul initializeI2C Function I2C1BRG = 39; TRISBbits.TRISB9 = 1; // SDA TRISBbits.TRISB8 = 1; // SCL OSCCON = 0x0000; //CLKDIV = 0x0700; REFOCON = 0x0000; //This function will initialize the I2C(1) peripheral. //Now we will initialise the I2C peripheral for Master Mode, No Slew Rate //Control, and leave the peripheral switched off. I2C1CON = 0x1200; I2C1RCV = 0x0000; I2C1TRN = 0x0000; //Now we can enable the peripheral I2C1CON = 0x9200; // I2CEN, SCLREL, DISSLW unsigned int StartI2C(void) { //This function generates an I2C start condition and returns status //of the Start. I2C1CONbits.SEN = 1; //Generate Start COndition while (I2C1CONbits.SEN); //Wait for Start COndition return (I2C1STATbits.S); //Optionally return status } unsigned int StopI2C(void) { //This function generates an I2C stop condition and returns status //of the Stop. I2C1CONbits.PEN = 1; //Generate Stop Condition while (I2C1CONbits.PEN); //Wait for Stop return (I2C1STATbits.P); //Optional - return status } unsigned int WriteI2C_Buffer(unsigned char byte) { //This function transmits the byte passed to the function //while (I2C1STATbits.TRSTAT); //Wait for bus to be idle I2C1TRN = byte; //Load byte to I2C1 Transmit buffer while (I2C1STATbits.TBF); //wait for data transmission return 0; } unsigned int IdleI2C(void) { while (I2C1STATbits.TRSTAT); //Wait for bus Idle return 0; } unsigned int WriteI2C(unsigned char ControlByte, unsigned char LowAdd, unsigned char data, unsigned char cnt) { unsigned int ErrorCode; IdleI2C(); //Ensure Module is Idle StartI2C(); //Generate Start COndition WriteI2C_Buffer(ControlByte); //Write Control byte IdleI2C(); ErrorCode = ACKStatus(); //Return ACK Status WriteI2C_Buffer(LowAdd); //Write Low Address IdleI2C(); ErrorCode = ACKStatus(); //Return ACK Status WriteI2C_Buffer(data); //Write Data IdleI2C(); StopI2C(); //Initiate Stop Condition return (ErrorCode); } |
|
相关推荐
1个回答
|
|
你曾经读过这个装置吗?这通常是由一个错误的读例程引起的,忽略了在停止之前发送一个NAK。这可以通过禁用I2C外围设备、浮动SDA和在100 kHz(或更慢)上切换SCL 9次来恢复。您的写入代码不好。每次写入之后,IFACKSTATUSSE()指示收到一个NAK,您应该跳过所有的以下写入,直接发送停止。
以上来自于百度翻译 以下为原文 Do you ever read from the device? That's usually caused by a faulty read routine neglecting to send a NAK before the STOP. That can be recoverd from by disabling the I2C peripheral, floating SDA, and toggling SCL 9 times at 100 KHz (or slower). Your write code is not good. After each write, if ACKStatus() indicates a NAK was received, you should skip all the following writes and go straight to sending the STOP. |
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 19:39 , Processed in 1.071247 second(s), Total 45, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号