cancel
Showing results for 
Search instead for 
Did you mean: 

SMBus problems with interrupt

Posted on June 20, 2011 at 14:55

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

&sharpinclude ''SMBus_management.h''

&sharpinclude ''GPIO_initialization.h''

&sharpinclude ''stm32f10x_i2c.h''

&sharpinclude ''stm32f10x_nvic.h''

&sharpinclude ''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);

*/

#smbus-irq-i2c-nvic
3 REPLIES 3
Posted on June 20, 2011 at 16:54

Look at some of the STM32 library examples, including earlier FW releases, and bundled with Keil, IAR, etc.

Get your startup sequencing cleaned up

Set up the clocks

Set up the GPIOs

Set up the NVIC

Set up the I2C

Enable the I2C

Enable the I2C Interrupts

The Interrupt Handlers MUST clear the pending IRQ, by reading I2C_GetLastEvent() or whatever. Failure to clear/handle interrupts properly will preclude any further operation of the platform.

Look at the SMBus on a scope/analyzer, look at the SMBus loop-back example from the ST firmware library, try that first, and work from there. Try the sequencing/transaction without interrupts first. Figure out where in the sequence/protocol things are falling over. Do you need ARP and PEC?

Provide a complete harness and context for your code, it doesn't need to be huge, just complete. The code you have presented is not useable/buildable as is.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 20, 2011 at 17:34

you're right, but i don't have found example with smbus and interrupt.

I think that in my application i will need using interrupt.

I don't need ARP and PEC

I will try some code in the library...thank you!!!