/** * @brief User callback that manages the Timeout error. * @param pDevInitStruct . * @retval None. */ uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct) { /* Deinitialize peripheral */ sEE_DeInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]) ; /* Initialize peripherals for communication with sEE */ sEE_StructInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]); sEE_Init(sEE_DevStructures[pDevInitStruct->CPAL_Dev]); sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState = sEE_STATE_ERROR; return CPAL_PASS; }
/** * @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) { /* Stop timeout countdown */ sEE_DevStructures[pDevInstance]->sEE_CPALStructure->wCPAL_Timeout = CPAL_I2C_TIMEOUT_DEFAULT; /* Deinitialize peripheral */ sEE_DeInit(sEE_DevStructures[pDevInstance]) ; /* Initialize peripherals for communication with sEE */ sEE_StructInit(sEE_DevStructures[pDevInstance]); sEE_Init(sEE_DevStructures[pDevInstance]); sEE_DevStructures[pDevInstance]->sEEState = sEE_STATE_ERROR; }
/** * @brief Basic management of the timeout situation. * @param None. * @retval 0. */ uint32_t sEE_TIMEOUT_UserCallback(void) { /* The following code allows I2C error recovery and return to normal communication if the error source doesn’t still exist (ie. hardware issue..) */ /* Reinitialize all resources */ sEE_DeInit(); sEE_Init(); /* At this stage the I2C error should be recovered and device can communicate again (except if the error source still exist). User can implement mechanism (ex. test on max trial number) to manage situation when the I2C can't recover from current error. */ return 0; }
/** * @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) { /* Generate STOP */ __CPAL_I2C_HAL_STOP(pDevInstance); LCD_DisplayStringLine(Line6, (uint8_t*)" Device Err occurred "); /* Deinitialize peripheral */ sEE_DeInit(sEE_DevStructures[pDevInstance]) ; /* Initialize peripheral To communication with sEE and IOE and TempSensor*/ sEE_StructInit(sEE_DevStructures[pDevInstance]); sEE_Init(sEE_DevStructures[pDevInstance]); /* Initialize sEE state */ if ((sEE_DevStructures[pDevInstance]->sEEState == sEE_STATE_WRITING)\ || (sEE_DevStructures[pDevInstance]->sEEState == sEE_STATE_READING)) { sEE_DevStructures[pDevInstance]->sEEState = sEE_STATE_ERROR; } }
/** * @brief User callback that manages the Timeout error. * @param pDevInitStruct . * @retval None. */ uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct) { /* Generate STOP */ __CPAL_I2C_HAL_STOP(pDevInitStruct->CPAL_Dev); LCD_DisplayStringLine(Line7, (uint8_t*)"Timeout Err occurred "); /* Deinitialize peripheral */ sEE_DeInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]) ; /* Initialize peripheral to communication with sEE and IOE and TempSensor */ sEE_StructInit(sEE_DevStructures[pDevInitStruct->CPAL_Dev]); sEE_Init(sEE_DevStructures[pDevInitStruct->CPAL_Dev]); /* Initialize sEE state */ if ((sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState == sEE_STATE_WRITING)\ || (sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState == sEE_STATE_READING)) { sEE_DevStructures[pDevInitStruct->CPAL_Dev]->sEEState = sEE_STATE_ERROR; } return CPAL_PASS; }
/** * @brief Main program. * @param None * @retval None */ void SPI_EEPROM_Example(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ /* Initialize the SPI EEPROM driver ----------------------------------------*/ sEE_Init(); /* First write in the memory followed by a read of the written data --------*/ /* Write on SPI EEPROM from sEE_WRITE_ADDRESS1 */ sEE_WriteBuffer(Tx1Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1); /* Wait for EEPROM standby state */ sEE_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE1; /* Read from SPI EEPROM from sEE_READ_ADDRESS1 */ sEE_ReadBuffer(Rx1Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead)); /* Check if the data written to the memory is read correctly */ TransferStatus1 = Buffercmp(Tx1Buffer, Rx1Buffer, BUFFER_SIZE1); /* Second write in the memory followed by a read of the written data -------*/ /* Write on SPI EEPROM from sEE_WRITE_ADDRESS2 */ sEE_WriteBuffer(Tx2Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2); /* Wait for EEPROM standby state */ sEE_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE2; /* Read from SPI EEPROM from sEE_READ_ADDRESS2 */ sEE_ReadBuffer(Rx2Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead)); /* Check if the data written to the memory is read correctly */ TransferStatus2 = Buffercmp(Tx2Buffer, Rx2Buffer, BUFFER_SIZE2); #ifdef ENABLE_LCD_MSG_DISPLAY /* Initialize the LCD screen for information display */ STM32303C_LCD_Init(); LCD_Clear(LCD_COLOR_BLUE); LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, "SMT32F30x FW Library"); LCD_DisplayStringLine(LCD_LINE_1, " EEPROM Example "); /* TransferStatus1 = PASSED, if the transmitted and received data to/from the EEPROM are the same */ /* TransferStatus1 = FAILED, if the transmitted and received data to/from the EEPROM are different */ if (TransferStatus1 == PASSED) { LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED "); } else { LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED "); } /* TransferStatus2 = PASSED, if the transmitted and received data to/from the EEPROM are the same */ /* TransferStatus2 = FAILED, if the transmitted and received data to/from the EEPROM are different */ if (TransferStatus2 == PASSED) { LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 PASSED "); } else { LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 FAILED "); } #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Free all used resources */ sEE_DeInit(); while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ #ifdef ENABLE_LCD_MSG_DISPLAY /* Initialize the LCD screen for information display */ #ifdef USE_STM32L152D_EVAL STM32L152D_LCD_Init(); #else STM32L152_LCD_Init(); #endif LCD_Clear(LCD_COLOR_BLUE); LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, "SMT32L1xx FW Library"); LCD_DisplayStringLine(LCD_LINE_1, " EEPROM Example "); #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Initialize the I2C EEPROM driver ----------------------------------------*/ sEE_Init(); /* First write in the memory followed by a read of the written data --------*/ /* Write on I2C EEPROM from sEE_WRITE_ADDRESS1 */ sEE_WriteBuffer(Tx1_Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1); /* Wait for EEPROM standby state */ sEE_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE1; /* Read from I2C EEPROM from sEE_READ_ADDRESS1 */ sEE_ReadBuffer(Rx1_Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead)); /* Starting from this point, if the requested number of data is higher than 1, then only the DMA is managing the data transfer. Meanwhile, CPU is free to perform other tasks: // Add your code here: //... //... For simplicity reasons, this example is just waiting till the end of the transfer. */ #ifdef ENABLE_LCD_MSG_DISPLAY LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 Ongoing "); #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler resets the variable holding the number of data to be read) */ while (NumDataRead > 0) {} /* Check if the data written to the memory is read correctly */ TransferStatus1 = Buffercmp(Tx1_Buffer, Rx1_Buffer, BUFFER_SIZE1); /* TransferStatus1 = PASSED, if the transmitted and received data to/from the EEPROM are the same */ /* TransferStatus1 = FAILED, if the transmitted and received data to/from the EEPROM are different */ #ifdef ENABLE_LCD_MSG_DISPLAY if (TransferStatus1 == PASSED) { LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED "); } else { LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED "); } #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Second write in the memory followed by a read of the written data -------*/ /* Write on I2C EEPROM from sEE_WRITE_ADDRESS2 */ sEE_WriteBuffer(Tx2_Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2); /* Wait for EEPROM standby state */ sEE_WaitEepromStandbyState(); /* Set the Number of data to be read */ NumDataRead = BUFFER_SIZE2; /* Read from I2C EEPROM from sEE_READ_ADDRESS2 */ sEE_ReadBuffer(Rx2_Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead)); /* Starting from this point, if the requested number of data is higher than 1, then only the DMA is managing the data transfer. Meanwhile, CPU is free to perform other tasks: // Add your code here: //... //... For simplicity reasons, this example is just waiting till the end of the transfer. */ #ifdef ENABLE_LCD_MSG_DISPLAY LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 Ongoing "); #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler resets the variable holding the number of data to be read) */ while (NumDataRead > 0) {} /* Check if the data written to the memory is read correctly */ TransferStatus2 = Buffercmp(Tx2_Buffer, Rx2_Buffer, BUFFER_SIZE2); /* TransferStatus2 = PASSED, if the transmitted and received data to/from the EEPROM are the same */ /* TransferStatus2 = FAILED, if the transmitted and received data to/from the EEPROM are different */ #ifdef ENABLE_LCD_MSG_DISPLAY if (TransferStatus2 == PASSED) { LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 PASSED "); } else { LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 FAILED "); } #endif /* ENABLE_LCD_MSG_DISPLAY */ /* Free all used resources */ sEE_DeInit(); while (1) { } }