Microchip
直播中

李洪斌

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

有办法在不做POR的情况下重置线路吗?

大家好,我的第一篇文章,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)

王焕树

2019-4-15 14:30:36
你曾经读过这个装置吗?这通常是由一个错误的读例程引起的,忽略了在停止之前发送一个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.
 
 
 
举报

更多回帖

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