iic从机中断中stop事件中断移植没法触发到,波形用逻辑分析仪抓取了看起来是没问题的。请问是哪里出问题了?
static int slaveI2c1Enable(struct slaveI2cBus *bus, unsigned int slaveAddr, int bEnable)
{
if (!bEnable)
{
i2c_disable(I2C1);
rcu_periph_clock_disable(RCU_I2C1);
}
else
{
/* enable GPIOB clock */
rcu_periph_clock_enable(RCU_GPIOB);
/* enable I2C1 clock */
rcu_periph_clock_enable(RCU_I2C1);
/* connect PB10 to I2C1_SCL */
/* connect PB11 to I2C1_SDA */
gpio_init(GPIOB, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_11);
/* I2C clock configure */
i2c_clock_config(I2C1, 100000, I2C_DTCY_2);
/* I2C address configure */
i2c_mode_addr_config(I2C1, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, slaveAddr);
/* enable I2C1 */
i2c_enable(I2C1);
/* enable acknowledge */
i2c_ack_config(I2C1, I2C_ACK_ENABLE);
/* enable the I2C1 interrupt */
nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
nvic_irq_enable(I2C1_EV_IRQn, 0, 1);
nvic_irq_enable(I2C1_ER_IRQn, 0, 2);
i2c_interrupt_enable(I2C1, I2C_INT_ERR);
i2c_interrupt_enable(I2C1, I2C_INT_BUF);
i2c_interrupt_enable(I2C1, I2C_INT_EV);
}
return 0;
}
void I2C1_EV_IRQHandler(void)
{
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_ADDSEND))
{
/* clear the ADDSEND bit */
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_ADDSEND);
if (i2c1.start)
i2c1.start(&i2c1);
}
else if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_RBNE))
{
/* if reception data register is not empty ,I2C1 will read a data from I2C_DATA */
if (i2c1.rx)
i2c1.rx(&i2c1, i2c_data_receive(I2C1));
}
else if ((i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_TBE)) && (!i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_AERR)))
{
/* send a data byte */
unsigned char txValue = i2c1.txData ? (unsigned char)i2c1.txData(&i2c1) : 0x00;
i2c_data_transmit(I2C1, txValue);
}
else if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_STPDET))
{
/* clear the STPDET bit */
i2c_enable(I2C1);
if (i2c1.stop)
i2c1.stop(&i2c1);
}
}
void I2C1_ER_IRQHandler(void)
{
/* no acknowledge received */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_AERR))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_AERR);
/* SMBus alert */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_SMBALT))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_SMBALT);
/* bus timeout in SMBus mode */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_SMBTO))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_SMBTO);
/* over-run or under-run when SCL stretch is disabled */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_OUERR))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_OUERR);
/* arbitration lost */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_LOSTARB))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_LOSTARB);
/* bus error */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_BERR))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_BERR);
/* CRC value doesn't match */
if (i2c_interrupt_flag_get(I2C1, I2C_INT_FLAG_PECERR))
i2c_interrupt_flag_clear(I2C1, I2C_INT_FLAG_PECERR);
}
|