AnsweredAssumed Answered

Use STM32CubeMX generates the code of I2C3 of STM32F302C8T6, but it does not work properly

Question asked by Jiannong Zhou on Feb 17, 2018
Latest reply on Feb 23, 2018 by Jiannong Zhou

I used STM32CubeMX to generate the init code of I2C3 of STM32F302C8T6 and added the test code to send some date out by I2C3. but it does not work properly, the error message = "HAL_I2C_ERROR_TIMEOUT". Tried to use STM32CubeMX to generate the init code of I2C3 of STM32F302R8T6. the code works fine, the error message = "HAL_I2C_ERROR_AF". the test does not connect to a slave device, only use scope to see the waveform of I2C. 

 

the code:

 

/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c3;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* Buffer used for transmission */
#define I2C_ADDRESS 0x30F

uint8_t aTxBuffer[] = " ****I2C_TwoBoards communication based on Polling**** ****I2C_TwoBoards communication based on Polling**** ****I2C_TwoBoards communication based on Polling**** ";

/* Buffer used for reception */
uint8_t aRxBuffer[RXBUFFERSIZE];

 

int main(void)
{
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

 

 

/* Configure the system clock */
SystemClock_Config();

 

 

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C3_Init();


/* USER CODE BEGIN 2 */
/* While the I2C in reception process, user can transmit data through
"aTxBuffer" buffer */
/* Timeout is set to 1S */
while(HAL_I2C_Master_Transmit(&hi2c3, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 1000)!= HAL_OK)
{
    /* Error_Handler() function is called when Timout error occurs.
   When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
   Master restarts communication */
   if (HAL_I2C_GetError(&hi2c3) != HAL_I2C_ERROR_AF)
   {
      Error_Handler();
   }
}

 

Used the same "Drivers". I compared the code of both for STM32F302R8T6 and C8T6, only the difference is pins of I2C3. 

 

Why I2C3 does not work properly on STM32F302C8T6? 

 

thanks in advance!

 

Best regards,

Jiannong

Attachments

Outcomes