本帖最后由 kerb_huang 于 2024-7-27 12:31 编辑
GD32E230K8U6 QFN32封装, 使用PA11 PA12做I2C1从机, 不能进入中断,请问什么原因
// *********
// iic1;
/* enable GPIOA clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* connect PA11 to I2C1_SCL */
gpio_af_set(GPIOA, GPIO_AF_7, I2C1_SCL_PIN);
/* connect PA12 to I2C1_SDA */
gpio_af_set(GPIOA, GPIO_AF_6, I2C1_SDA_PIN);
/* configure GPIO pins of I2C1 */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, I2C1_SCL_PIN);
gpio_output_options_set(GPIOA, GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, I2C1_SCL_PIN);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, I2C1_SDA_PIN);
gpio_output_options_set(GPIOA, GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, I2C1_SDA_PIN);
/* enable I2C clock */
rcu_periph_clock_enable(RCU_I2C1);
i2c_deinit(I2C1);
/* configure I2C clock */
i2c_clock_config(I2C1, I2C_SPEED, I2C_DTCY_2);
/* configure I2C address */
i2c_mode_addr_config(I2C1, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, I2C1_SLAVE_ADDRESS7);
/* enable and set interrupt to the lowest priority */
nvic_irq_enable(I2C1_ER_IRQn, 2U);
nvic_irq_enable(I2C1_EV_IRQn, 2U);
// BUFIE, event interrupt enable ,error interrupt enable;
i2c_interrupt_enable(I2C1, I2C_INT_ERR);
i2c_interrupt_enable(I2C1, I2C_INT_EV );
i2c_interrupt_enable(I2C1, I2C_INT_BUF);
/* enable I2C1 */
i2c_enable(I2C1);
/* enable acknowledge */
i2c_ack_config(I2C1, I2C_ACK_ENABLE);
|