各位,我用STM32L05X官方寄存器版例程I2C初始化和中断函数,只能进一次I2C中断,大家帮看看哪里配置不对。
/**
* Brief This function configures I2C1, slave.
* Param None
* Retval None
*/
void Configure_I2C1_Slave(void)
{
/* Configure RCC for I2C1 */
/* (1) Enable the peripheral clock I2C1 */
/* (2) Use APBCLK for I2C CLK */
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; /* (1) */
RCC->CCIPR &= ~RCC_CCIPR_I2C1SEL; /* (2) */
/* Configure I2C1, slave */
/* (3) Timing register value is computed with the AN4235 xls file,
fast Mode @400kHz with I2CCLK = 16MHz, rise time = 100ns,
fall time = 10ns */
/* (4) Periph enable, address match interrupt enable, receive interrupt enable */
/* (5) 7-bit address = 0x5A */
/* (6) Enable own address 1 */
I2C1->TIMINGR = (unsigned int)0x00300619; /* (3) */
I2C1->CR1 = I2C_CR1_PE | I2C_CR1_RXIE | I2C_CR1_ADDRIE; /* (4) */
I2C1->OAR1 |= (unsigned int)(I2C1_OWN_ADDRESS << 1); /* (5) */
I2C1->OAR1 |= I2C_OAR1_OA1EN; /* (6) */
/* Configure IT */
/* (7) Set priority for I2C1_IRQn */
/* (8) Enable I2C1_IRQn */
NVIC_SetPriority(I2C1_IRQn, 0); /* (7) */
NVIC_EnableIRQ(I2C1_IRQn); /* (8) */
}
/**
* Brief This function handles I2C1 interrupt request.
* Param None
* Retval None
*/
void I2C1_IRQHandler(void)
{
unsigned int I2C_InterruptStatus = I2C1->ISR; /* Get interrupt status */
if((I2C_InterruptStatus & I2C_ISR_ADDR) == I2C_ISR_ADDR)
{
I2C1->ICR |= I2C_ICR_ADDRCF; /* Address match event */
}
else if((I2C_InterruptStatus & I2C_ISR_RXNE) == I2C_ISR_RXNE)
{
/* Read receive register, will clear RXNE flag */
CLearLinkErrorCnt();
if(iicRecDataFlag == FALSE)
{
iicRecBuf[iicRecBufIndex] = I2C1->RXDR;
iicRecBufIndex++;
if(iicRecBufIndex == IICWINFOLEN)
{
iicRecDataFlag = TRUE;
iicRecBufIndex = 0;
}
}
}
else
{
error = ERROR_I2C; /* Report an error */
NVIC_DisableIRQ(I2C1_IRQn); /* Disable I2C1_IRQn */
}
} |