2014-09-25 03:11 AM
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-hal2014-09-25 03:55 AM
Hi Gates,
I'm not sure I fully understand the issue you’re experiencing, could you please answer the following questions: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 package.Cheers,Heisenberg.2014-09-29 01:06 AM
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 thehttp://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.2014-09-29 02:12 AM
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