Due to a hardware design error, the CLK/Data pins on TWI bus was switched in different PCB versions. I want use software to dynamically detect the situation and switch the pins. But the code doesn't work. Could you help on this?
I am using 51822 and the SDK version is 9.0 and S110.
The following are related code:
uint8_t TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER=2;
uint8_t TWI_MASTER_CONFIG_DATA_PIN_NUMBER=1;
uint8_t who_am_i;
bool auto_correct_twi_pins()
{
twi_master_init();
mpu6050_register_read(REG_WHO_AM_I_Addr, &who_am_i, 1);
//if read correctly, who_am_i shall contains an valid WHOAMI ID.
if(who_am_i==Expected_who_am_I )
return true;
//switch twi CLK and Data pin number
uint8_t tmp;
tmp = TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER;
TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER = TWI_MASTER_CONFIG_DATA_PIN_NUMBER;
TWI_MASTER_CONFIG_DATA_PIN_NUMBER = tmp;
twi_master_init();
//try again to verify the pin order is correct
mpu6050_register_read(REG_WHO_AM_I_Addr, &who_am_i, 1);
if(who_am_i != Expected_who_am_I)
return false;
}
return true;
}