cancel
Showing results for 
Search instead for 
Did you mean: 

Hard fault on I2C initialization

Youssouf Coulibaly
Associate II
Posted on June 30, 2017 at 09:52

Hello,

First I am new in ST device, I only used Microchip PIC for 6 years.

So any advise or comment will be appreciated.

I am trying to use I2C interface on NucleoBoard F091RC1.

I2C_HandleTypeDef* hi2c1;

void i2cInit(I2C_HandleTypeDef* i2cHandler)

{

      // Assigned I2C handler pointer 

       hi2c1 = i2cHandler;

    // Call I2C init function 

      MX_I2C1_Init();

}

void MX_I2C1_Init(void)

{

hi2c1->Instance = I2C1;

      hi2c1->Init.Timing = 0x2000090E;

      hi2c1->Init.OwnAddress1 = 0;

      hi2c1->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

      hi2c1->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

      hi2c1->Init.OwnAddress2 = 0;

      hi2c1->Init.OwnAddress2Masks = I2C_OA2_NOMASK;

      hi2c1->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

      hi2c1->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

      if (HAL_I2C_Init(hi2c1) != HAL_OK)

      {

            //Error_Handler();

      }

      /**Configure Analogue filter

      */

      if (HAL_I2CEx_ConfigAnalogFilter(hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)

      {

            //Error_Handler();

      }

}

In debug mode my code generate an hardware fault event on the first line of

MX_I2C1_Init function

.

Would it be possible for someone to tell me what i am doing wrong ?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee
Posted on July 03, 2017 at 17:03

Hello

COULIBALY.Youssouf

,

Welcome to STM

Have a look to theworking

example within STM32F091RC-Nucleo available under

STM32CubeF0 firmware package:

STM32Cube_FW_F0_V1.8.0\Projects\STM32F091RC-Nucleo\Examples\I2C

You may re-use sections available in the example or get inspired from them.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

3 REPLIES 3
Imen.D
ST Employee
Posted on July 03, 2017 at 17:03

Hello

COULIBALY.Youssouf

,

Welcome to STM

Have a look to theworking

example within STM32F091RC-Nucleo available under

STM32CubeF0 firmware package:

STM32Cube_FW_F0_V1.8.0\Projects\STM32F091RC-Nucleo\Examples\I2C

You may re-use sections available in the example or get inspired from them.

Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on July 03, 2017 at 17:43

I would start with CubeMX and enable the I2C1, then generate the code. This way you can easily setup clocking as well as every peripheral need to be clocked.

Youssouf Coulibaly
Associate II
Posted on July 04, 2017 at 08:33

Hello Imen D,

Thanks a lot for your support. Now I get timer Interrupt. I have rewritten a weak function HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) in my cpp file.

Now I would lilke to do the same with HAL_DMA_TxCpltCallback(DMA_HandleTypeDef * hdma), but I cannot find any weak function with DMA complete callback.

Would it be possible to trigger a DMA complete without explicitly used a register callback function ?