diff --git a/armsrc/appmain.c b/armsrc/appmain.c index f59cc13a3..756ca4f4f 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -2608,7 +2608,7 @@ void __attribute__((noreturn)) AppMain(void) { #endif #ifdef WITH_SMARTCARD - I2C_init(); + I2C_init(false); #endif #ifdef WITH_FPC_USART diff --git a/armsrc/i2c.c b/armsrc/i2c.c index 6ede36b13..b9b536c24 100644 --- a/armsrc/i2c.c +++ b/armsrc/i2c.c @@ -91,7 +91,7 @@ void I2C_recovery(void) { DbpString("I2C bus recovery complete"); } -void I2C_init(void) { +void I2C_init(bool has_ticks) { // Configure reset pin, close up pull up, push-pull output, default high AT91C_BASE_PIOA->PIO_PPUDR = GPIO_RST; AT91C_BASE_PIOA->PIO_MDDR = GPIO_RST; @@ -106,6 +106,10 @@ void I2C_init(void) { AT91C_BASE_PIOA->PIO_OER |= (GPIO_SCL | GPIO_SDA | GPIO_RST); AT91C_BASE_PIOA->PIO_PER |= (GPIO_SCL | GPIO_SDA | GPIO_RST); + if (has_ticks) { + WaitMS(2); + } + bool isok = (SCL_read && SDA_read); if (isok == false) I2C_recovery(); @@ -133,7 +137,7 @@ void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA) { // Note: the SIM_Adapter will not enter the main program after power up. Please run this function before use SIM_Adapter. void I2C_Reset_EnterMainProgram(void) { StartTicks(); - I2C_init(); + I2C_init(true); I2C_SetResetStatus(0, 0, 0); WaitMS(30); I2C_SetResetStatus(1, 0, 0); @@ -146,7 +150,7 @@ void I2C_Reset_EnterMainProgram(void) { // Reserve for firmware update. void I2C_Reset_EnterBootloader(void) { StartTicks(); - I2C_init(); + I2C_init(true); I2C_SetResetStatus(0, 1, 1); WaitMS(100); I2C_SetResetStatus(1, 1, 1); diff --git a/armsrc/i2c.h b/armsrc/i2c.h index 2ce051bd7..972704c1b 100644 --- a/armsrc/i2c.h +++ b/armsrc/i2c.h @@ -31,7 +31,7 @@ #define I2C_DEVICE_CMD_SEND_T0 0x07 void I2C_recovery(void); -void I2C_init(void); +void I2C_init(bool has_ticks); void I2C_Reset(void); void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA);