已测试一周,目前无死机现象出现,验证恢复状态良好,这个问题算解决了。。提供代码如下:- void count_delay_us(uint32_t time_us)
- {
- uint32_t i;
- uint32_t cons = 17;
-
- for(i=0; i<time_us; i++)
- {
- while(cons--) ;
- cons = 22;
- }
-
- return;
- }
- void I2C_recover(void)
- {
- int i;
- //first: changed the scl to gpio out
- SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA3MFP_Msk | SYS_GPA_MFPL_PA2MFP_Msk);
- SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_GPIO | SYS_GPA_MFPL_PA2MFP_GPIO);
- delayms(1);
- GPIO_SetMode(PA, BIT3, GPIO_MODE_OUTPUT);
- PA3=0;
-
- //second: send nine clock
- delayms(1);
- for(i=0; i<10; i++)
- //while(1)
- {
- PA3=1;
- count_delay_us(10);
- PA3=0;
- count_delay_us(10);
- }
- //PA3=1;
- delayms(1);
- return;
- }
- int I2C_Conifiguration(void)
- {
- //I2C_recover();
- SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA3MFP_Msk | SYS_GPA_MFPL_PA2MFP_Msk);
- SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_I2C0_SCL | SYS_GPA_MFPL_PA2MFP_I2C0_SDA);
- /* Reset I2C0 */
- //SYS_ResetModule(I2C0_RST);
-
- /* Open I2C module and set bus clock */
- I2C_Open(I2C0, 80000);
-
-
-
- /* Enable I2C interrupt */
- I2C_EnableInt(I2C0);
- NVIC_EnableIRQ(I2C0_IRQn);
- I2C_SMBusOpen(I2C0, I2C_SMBH_ENABLE);
- I2C_SMBusPECTxEnable(I2C0, I2C_PECTX_DISABLE);
- //I2C_SMBUS_ACK_MANUAL(I2C0);
- I2C_SMBUS_ACK_AUTO(I2C0);
- //SYS_ResetModule(I2C0_RST);
-
- return 0;
- }
- void I2C_deinit(void)
- {
- /* Disable I2C0 interrupt and clear corresponding NVIC bit */
- I2C_DisableInt(I2C0);
- NVIC_DisableIRQ(I2C0_IRQn);
- /* Disable I2C0 and close I2C0 clock */
- I2C_Close(I2C0);
- //CLK_DisableModuleClock(I2C0_MODULE);
- //i2c all use ,donot close its clock
-
- }
复制代码
|