AnsweredAssumed Answered

STM32F103 on STM32-SK IAR Board - I2C - Bus Error - BusFault_Handler

Question asked by giampa_.valerio on Aug 17, 2011
Latest reply on Aug 17, 2011 by Clive One
Dear collegue,
I have lunched the example project about I2C simple communication with interrupt that we can find in the UM0427 (user manual about firmware lib v2.0.3).
The simple application is based on the main showed below.
IWhen the program execute I2C1 Start Condition, a Bus Error occour and the cpu go in the BusFault_Handler.
Why there is this bus error?...How can I do to delete this error?

int main(void)
{
#ifdef DEBUG
  debug();
#endif

  /* System clocks configuration ---------------------------------------------*/
  RCC_Configuration();

  /* NVIC configuration ------------------------------------------------------*/
  NVIC_Configuration();

  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();

  /* Enable I2C1 and I2C2 ----------------------------------------------------*/
  I2C_Cmd(I2C1, ENABLE);
  I2C_Cmd(I2C2, ENABLE);

  /* I2C1 configuration ------------------------------------------------------*/
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;
  I2C_Init(I2C1, &I2C_InitStructure);
  /* I2C2 configuration ------------------------------------------------------*/
  I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS7;
  I2C_Init(I2C2, &I2C_InitStructure);

  I2C_CalculatePEC(I2C1, ENABLE);  
  I2C_CalculatePEC(I2C2, ENABLE);  
  
  /* Enable I2C1 event and buffer interrupts */
  I2C_ITConfig(I2C1, I2C_IT_EVT | I2C_IT_BUF, ENABLE);
  /* Enable I2C1 event and buffer interrupts */
  I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF, ENABLE);
  
  /*----- Transmission Phase -------------------------------------------------*/
  /* Set data direction to transmitter */
  Direction = Transmitter;
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);

  /* Wait until all data and the PEC value are received */
  /* I2C2_Buffer_Rx buffer will contain the data plus the PEC value */
  while(Rx2_Idx < Tx1BufferSize)
  {
  }
  
  /* Check the corectness of the I2C1 transmitted data */
  TransferStatus1 = Buffercmp(I2C1_Buffer_Tx, I2C2_Buffer_Rx, Tx1BufferSize);
  /* TransferStatus1 = PASSED, if the transmitted and received data
     are equal */
  /* TransferStatus1 = FAILED, if the transmitted and received data 
     are different */
     

  /*----- Reception Phase --------------------------------------------------*/
  /* Re-configure and enable I2C1 event interrupt to have the higher priority */
  NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
 
 
  /* Wait until end of Slave transmission */
  while(Rx1_Idx < Tx2BufferSize)
  {
  }

  /* Check the corectness of the I2C1 received data */
  TransferStatus2 = Buffercmp(I2C2_Buffer_Tx, I2C1_Buffer_Rx, Tx2BufferSize);
  /* TransferStatus2 = PASSED, if the transmitted and received data
     are equal */
  /* TransferStatus2 = FAILED, if the transmitted and received data 
     are different */
   
  while(1)
  {
  }
}

Outcomes