/** * @brief User callback that manages the I2C device errors. * @note Make sure that the define USE_SINGLE_ERROR_CALLBACK is uncommented in * the cpal_conf.h file, otherwise this callback will not be functional. * @param pDevInitStruct. * @param DeviceError. * @retval None */ void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t DeviceError) { /* if an Acknowledge failure error occurred */ if (DeviceError == CPAL_I2C_ERR_AF ) { LCD_DisplayStringLine(Line9, (uint8_t*)" Slave Not yet Ready"); } else { LCD_DisplayStringLine(Line9, (uint8_t*)" Device Err occurred "); } /* Update CPAL states */ I2C_DevStructures[pDevInstance]->CPAL_State = CPAL_STATE_READY; I2C_DevStructures[pDevInstance]->wCPAL_DevError = CPAL_I2C_ERR_NONE; /* Deinitialize CPAL device */ CPAL_I2C_DeInit(I2C_DevStructures[pDevInstance]); /* Initialize CPAL device with the selected parameters */ CPAL_I2C_Init(I2C_DevStructures[pDevInstance]); /* Switch the LCD write color */ Switch_ErrorColor(); ActionState = ACTION_NONE; }
/** * @brief User callback that manages the Timeout error. * @param pDevInitStruct . * @retval None. */ uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct) { I2C_DevStructure.CPAL_State = CPAL_STATE_READY; I2C_DevStructure.wCPAL_DevError = CPAL_I2C_ERR_NONE ; /* No Device Error */ I2C_DevStructure.wCPAL_Timeout = CPAL_I2C_TIMEOUT_DEFAULT; /* Stop timeout countdown */ /* DeInitialize CPAL device */ CPAL_I2C_DeInit(&I2C_DevStructure); /* Initialize CPAL device with the selected parameters */ CPAL_I2C_Init(pDevInitStruct); /* Switch the LCD write color */ Switch_ErrorColor(); LCD_DisplayStringLine(Line9, (uint8_t*)" Timeout Recovered "); ActionState = ACTION_NONE; return CPAL_PASS; }