AnsweredAssumed Answered

SMBus problems with interrupt

Question asked by Nico on Jun 20, 2011
Latest reply on Jun 20, 2011 by Nico
i'm implementing a SMBus between stm32f103 (slave) on STM32-SK development board and omap3 (master).
I send to slave a write command , but the slave does't start the interrupt I2C1_EV_IRQHandler. Why??
Thank you for your answer.


/* Includes ------------------------------------------------------------------*/
#include "SMBus_management.h"
#include "GPIO_initialization.h"
#include "stm32f10x_i2c.h"
#include "stm32f10x_nvic.h"
#include "stm32f10x_lib.h"



/* Private variables ---------------------------------------------------------*/



/* Global variables ---------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
 /*******************************************************************************
* Function Name  : SMBus_Initialization();
* Description    : Inizializza gpio e struttura SMBus su I2c1, con i relativi interrupt
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/

void SMBus_Init(void){
 
  /* Da inserire dove si inizializzano i gpio
    RCC_APB2PeriphClockCmd(     RCC_APB2Periph_GPIOB |
                           RCC_APB2Periph_AFIO, ENABLE );
  */
 
 /*Da inserire dove si inizializzano i gpio->Imposto gpioB_pin6e7 come GPIO_Mode_AF_OD
  //GPIOB
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 */

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

 
   
  /* 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);  

  /* 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 = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);   

  /* Gestisco l'interrupt I2C1_ER_IRQChannel (gestione eventi) associato SMBus */
 
  NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQChannel ;
  //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);  
   
  I2C_ITConfig(I2C1, I2C_IT_EVT , ENABLE);
  I2C_ITConfig(I2C1, I2C_IT_BUF , ENABLE);
  I2C_ITConfig(I2C1, I2C_IT_ERR , ENABLE);

 
   

  /* Enable I2C1 and I2C2 ----------------------------------------------------*/
  I2C_Cmd(I2C1, ENABLE);
  I2C_DMACmd(I2C1,ENABLE); // forse non necessario

/*
  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)
{
GPIO_WriteBit(GPIOA,GPIO_Pin_4 ,(Bit_RESET));

}

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

void I2C1_ER_IRQHandler(void)
{
 GPIO_WriteBit(GPIOA,GPIO_Pin_5 ,(Bit_RESET));
}
/*

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