AnsweredAssumed Answered

STM32 SMBus I2C problems

Question asked by Nico on Jun 17, 2011
Latest reply on Jun 17, 2011 by Nico
Hi everyone..i've a probel with SMBus imlementation;
The following code is imlemented like a main function.
I need to ude a stm32 like a slave and the master is a  TI OMAP 3530.
The problem is that after   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4
the program will block the execution.

Thank you for anwering.
Naicopi


/*___________________________________________________________________*/
// Enable GPIO clock and release reset
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC | 
                         RCC_APB2Periph_AFIO, 
                         ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC |
                         RCC_APB2Periph_AFIO, 
                         DISABLE);
GPIO_InitTypeDef GPIO_InitStructure;
//GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_Init(GPIOC, &GPIO_InitStructure); 
  /*Associo GPIOC_PIN6e7 GPIO_remap_I2c1*/
  GPIO_PinRemapConfig( GPIO_Remap_I2C1 , ENABLE ); 
 

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);  
   NVIC_ClearIRQChannelPendingBit(I2C1_EV_IRQChannel);
   NVIC_ClearIRQChannelPendingBit(I2C1_ER_IRQChannel);
 

  /* Enable I2C1 and I2C2 ----------------------------------------------------*/
   I2C_Cmd(I2C1, ENABLE);
   
  /* I2C1 configuration: SMBus Slave ------------------------------------------*/
  I2C_InitTypeDef  I2C_InitStructure;
  I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusDevice;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = 0x30;//indirizzo dello slave
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = 100000; // 100KHz, come SMBus omap
  I2C_Init(I2C1, &I2C_InitStructure);  
  I2C_ITConfig(I2C1, (I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR), DISABLE);
  /* Gestisco l'interrupt I2C1_EV_IRQChannel (gestione eventi) associato SMBus */
 
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQChannel ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);   
 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQChannel ;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);  
   



I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_OVR);
I2C_ClearITPendingBit(I2C1,I2C_IT_AF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ARLO);
I2C_ClearITPendingBit(I2C1,I2C_IT_BERR);
I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADD10);
I2C_ClearITPendingBit(I2C1,I2C_IT_BTF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADDR);
I2C_ClearITPendingBit(I2C1,I2C_IT_SB);

}

/*******************************************************************************
* Function Name  : I2C1_EV_IRQHandler
* Description    : This function handles I2C1 Event interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/

void I2C1_EV_IRQHandler(void)
{
  I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_OVR);
I2C_ClearITPendingBit(I2C1,I2C_IT_AF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ARLO);
I2C_ClearITPendingBit(I2C1,I2C_IT_BERR);
I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADD10);
I2C_ClearITPendingBit(I2C1,I2C_IT_BTF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADDR);

I2C_ClearITPendingBit(I2C1,I2C_IT_SB);
    GPIO_WriteBit(GPIOA,GPIO_Pin_4 ,(Bit_RESET));
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_OVR);
I2C_ClearITPendingBit(I2C1,I2C_IT_AF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ARLO);
I2C_ClearITPendingBit(I2C1,I2C_IT_BERR);
I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADD10);
I2C_ClearITPendingBit(I2C1,I2C_IT_BTF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADDR);

I2C_ClearITPendingBit(I2C1,I2C_IT_SB);
}

/*******************************************************************************
* Function Name  : I2C1_ER_IRQHandler
* Description    : This function handles I2C1 Error interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/

void I2C1_ER_IRQHandler(void)
{
  I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_OVR);
I2C_ClearITPendingBit(I2C1,I2C_IT_AF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ARLO);
I2C_ClearITPendingBit(I2C1,I2C_IT_BERR);
I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADD10);
I2C_ClearITPendingBit(I2C1,I2C_IT_BTF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADDR);

I2C_ClearITPendingBit(I2C1,I2C_IT_SB);
    //GPIO_WriteBit(GPIOA,GPIO_Pin_5 ,(Bit_RESET));
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_TIMEOUT);
I2C_ClearITPendingBit(I2C1,I2C_IT_OVR);
I2C_ClearITPendingBit(I2C1,I2C_IT_AF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ARLO);
I2C_ClearITPendingBit(I2C1,I2C_IT_BERR);
I2C_ClearITPendingBit(I2C1,I2C_IT_STOPF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADD10);
I2C_ClearITPendingBit(I2C1,I2C_IT_BTF);
I2C_ClearITPendingBit(I2C1,I2C_IT_ADDR);

I2C_ClearITPendingBit(I2C1,I2C_IT_SB);
}

Outcomes