cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303 discovery I2c interrupts are not working.

Channamallesh Hiremath
Associate II
Posted on May 16, 2018 at 04:22

Hello,

I have modified STM32F303 discovery demonstration code to use I2C interrupts instead of polling mode.

For some reason, I am not getting any interrupts. 

Can someone check my code? 

I added a function call to enable interrupts and populated the interrupt vector code. 

/* LSM303DLHC_I2C Peripheral Enable */

I2C_Cmd(LSM303DLHC_I2C, ENABLE);

I2C_ITConfig(LSM303DLHC_I2C, I2C_IT_ERRI|I2C_IT_TCI|I2C_IT_STOPI|I2C_IT_NACKI|I2C_IT_ADDRI|I2C_IT_RXI|I2C_IT_TXI, ENABLE);

// interrupt handler

void I2C1_ER_IRQHandler(void)

{

I2C_ClearFlag(LSM303DLHC_I2C, I2C_FLAG_BERR|I2C_FLAG_ARLO|I2C_FLAG_OVR);

}

__IO uint32_t interrupt_count = 0;

void I2C1_EV_IRQHandler(void)

{

interrupt_count = interrupt_count++;

if(MasterMode==MASTER_MODE_TRANSMITTER){

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TXIS)==SET)&&(i2c_state_g==0))

{

I2C_SendData(LSM303DLHC_I2C, (uint8_t) RegAddr_g);

i2c_state_g = 1;

interrupt_count = interrupt_count+0x100;

}

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TCR)==SET)&&(i2c_state_g==1))

{

/* Configure slave address, nbytes, reload, end mode and start or stop generation */

I2C_TransferHandling(LSM303DLHC_I2C, DeviceAddr_g, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);

i2c_state_g = 2;

interrupt_count = interrupt_count+0x800;

}

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TXIS) == SET)&&(i2c_state_g==2))

{

/* Write data to TXDR */

I2C_SendData(LSM303DLHC_I2C, *pBuffer_g);

i2c_state_g = 3;

interrupt_count = interrupt_count+0x1000;

}

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_STOPF) == SET)&&(i2c_state_g==3))

{

I2C_ClearFlag(LSM303DLHC_I2C, I2C_ICR_STOPCF);

i2c_state_g = 0;

i2c_busy_g = 0;

interrupt_count = interrupt_count+0x8000;

}

}else{

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TXIS) == SET)&&(i2c_state_g==0))

{

if(NumByteToRead_g>1)

RegAddr_g |= 0x80;

/* Send Register address */

I2C_SendData(LSM303DLHC_I2C, (uint8_t)RegAddr_g);

i2c_state_g = 1;

}

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TC) == SET)&&(i2c_state_g==1))

{

/* Configure slave address, nbytes, reload, end mode and start or stop generation */

I2C_TransferHandling(LSM303DLHC_I2C, DeviceAddr_g, NumByteToRead_g, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);

i2c_state_g = 2;

}

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_RXNE) == SET)&&(i2c_state_g==2))

{

/* Read data from RXDR */

*pBuffer_g = I2C_ReceiveData(LSM303DLHC_I2C);

pBuffer_g++;

NumByteToRead_g--;

if(NumByteToRead_g==0)

{

i2c_state_g = 3;

}

}

if((I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_STOPF)==SET)&&(i2c_state_g==3))

{

/* Clear STOPF flag */

I2C_ClearFlag(LSM303DLHC_I2C, I2C_ICR_STOPCF);

i2c_state_g = 0;

i2c_busy_g = 0;

}

}

}

0 REPLIES 0