cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with I2C on STM32F030R8T6 using STM32F0xx HAL drivers library

gaetanbusson
Associate II
Posted on September 25, 2014 at 12:11

Hello,

I am trying to use I2C master communication with the STM32F030R8T8 that is on the STM32F0308DISCOVERY kit. I have used STM32CubeMX to generate the following initialization code:


/* I2C1 init function */

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_DISABLED;

hi2c1.Init.OwnAddress2 = 0;

hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;

hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;

hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;

HAL_I2C_Init(&hi2c1);


/**Configure Analogue filter 

*/

HAL_I2CEx_AnalogFilter_Config(&hi2c1, I2C_ANALOGFILTER_ENABLED);


}

Then, I have tried to write a byte on I2C by using this function:

1.
HAL_I2C_Master_Transmit_IT(&hi2c1, 117, &data, 1);

After this line, my program doesn’t step over because the following handlers are called:

-

BusFault_Handler

-

DebugMon_Handler

-

HardFault_Handler

What’s wrong with my code?

#i2c-stm32f030r8t-stm32f0xx-hal
3 REPLIES 3
Posted on September 25, 2014 at 12:55

Hi Gates,

I'm not sure I fully understand the issue you’re experiencing, could you please answer the following questions:

  • What is you I2C Slave side you're communicating with ? Is it an other STM32F0308-Discovery board ?
  • You have listed 3 errors in your post, which one are you finding exactly ?

PS: To have more insight into I2C Data buffer transmission and reception using Interrupt please check the following example:

\Projects\STM32F0308-Discovery\Examples\I2C\I2C_TwoBoards_ComIT within the

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897/PF260612?icmp=pf260612_pron_nb_jun2014&sc=stm32cubef0-pr#

package.

Cheers,

Heisenberg.

gaetanbusson
Associate II
Posted on September 29, 2014 at 10:06

Hi Heisenberg,

I’ve got an IO expander (slave device) on another board that I’m trying to communicate with. I connected this board on the STM32F0308DISCOVERY kit but there was a problem with communication. I finally implemented the 3 functions that were supposed to be called: BusFault_Handler, DebugMon_Handler and HardFault_Handler. I’ve put a breakpoint on each functions and only HardFault_Handler was called.

I had a look on the example codes you indicate me and I finally found my problem: the row OwnAddress1 of the I2C_HandleTypeDef structure was set to zero. When I've put a non-zero value, the problem have disappeared.

By the way, I am using the

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00113898.pdf

for the STM32L0xx because I am unable to find the real datasheet for STM32F0xx MCUs. Do you know where I can find it?

Thank you for your help!

Gates.

Posted on September 29, 2014 at 11:12

Hi Gates,

Ok, Good ! You've found the issue you've committed.

Concerning the the STM32CubeF0 HAL drivers description document is under finalization and will be online as soon as possible.

Do, click ''Mark as helpful post 0690X00000605AeQAI.png'', if any of my replies helps solve your problem.

Regards,

Heisenberg.