cancel
Showing results for 
Search instead for 
Did you mean: 

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

Jiannong Zhou
Associate II
Posted on February 17, 2018 at 16:19

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

4 REPLIES 4
Jiannong Zhou
Associate II
Posted on February 20, 2018 at 03:17

Tested I2C2 with the same code, it works with

HAL_I2C_ERROR_AF error as it was not connected to any slave device. Tapped the SCL and SDA, can see the waveform. 

Do anybody know what the reason is?

regards,

Jiannong

Posted on February 22, 2018 at 05:14

STM32 centric questions should be posted to the

https://community.st.com/community/stm32-community/stm32-forum/activity

 where there is a better chance of getting a timely response.

The code would anticipate a second device to communicate with and one which acknowledges the 10-bit address used. A timeout suggests the remote/slave device is NOT responding. In reviewing the waveform you might wish to confirm/validate this.

I2C3 should work in a materially similar way to I2C2, I'm not using F3 parts, CubeMX or I2C, but the Data Sheet would be the controlling document describing the pins and AF mux settings suitable for a connection. The settings for the pins are presumably in the MSP file.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on February 22, 2018 at 10:02

Hi

Turvey.Clive.002

‌,

I moved discussion to correct forum. No need to duplicate entries.

Thanks for highlighting.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on February 23, 2018 at 10:52

Thanks Clive One and Amel N for your information and support!