ADD: re-initialize I2C after comms error

This commit is contained in:
Niklas Fauth
2018-05-11 22:04:12 +02:00
parent 8be7681ebf
commit ca525abe96
4 changed files with 1020 additions and 701 deletions

View File

@@ -76,13 +76,18 @@ void Nunchuck_Init() {
void Nunchuck_Read() {
i2cBuffer[0] = 0x00;
HAL_I2C_Master_Transmit(&hi2c2,0xA4,(uint8_t*)i2cBuffer, 1, 100);
HAL_Delay(2);
HAL_Delay(5);
if (HAL_I2C_Master_Receive(&hi2c2,0xA4,(uint8_t*)nunchuck_data, 6, 100) == HAL_OK) {
timeout = 0;
} else {
timeout++;
}
if (timeout > 3) {
HAL_Delay(50);
Nunchuck_Init();
}
//setScopeChannel(0, (int)nunchuck_data[0]);
//setScopeChannel(1, (int)nunchuck_data[1]);
//setScopeChannel(2, (int)nunchuck_data[5] & 1);