STM32F4 I2C从机无ACK应答问题技术求助
Let’s break down the root causes and fixes for your non-responsive I2C slave, starting with the most critical issue in your code:
1. Critical GPIO Pin Mapping Error
Looking at your GPIO setup, you assigned PB8 as I2C1 SCL—but for STM32F407VGT6, the correct I2C1 SCL pin is PB6, not PB8. PB8 is mapped to other peripherals (like SPI3 or TIM10), so your slave’s clock line isn’t connected to the I2C hardware at all. This explains why the slave never detects the master’s clock signal and can’t send an ACK.
Fix this by updating your GPIO configuration:
gpio_init.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6; // PB6 = SCL, PB7 = SDA // ... GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // Correct SCL pin mapping GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1); // SDA remains correct
2. Verify Slave Address Alignment
You set I2C_OwnAddress1 = 0x21 for the slave. Remember that I2C masters send 7-bit addresses shifted left by 1 (plus a read/write bit). So if your FT2232H is sending 0x42 (0x21 << 1) for write operations, that’s correct. You mentioned confirming the address is right, but double-check this shifted value matches what the master transmits to rule out any off-by-one errors.
3. Interrupt Handler Implementation
You enabled I2C1’s event, error, and buffer interrupts, but unimplemented interrupt handlers can lock up the peripheral. Even though the hardware should auto-send an ACK on address match, unhandled interrupts might prevent this behavior.
Add basic interrupt stubs to your code (expand them later as needed):
void I2C1_EV_IRQHandler(void) { // Handle address match event if (I2C_GetITStatus(I2C1, I2C_IT_ADDR) != RESET) { I2C_ClearITPendingBit(I2C1, I2C_IT_ADDR); // Clear the flag to proceed } } void I2C1_ER_IRQHandler(void) { // Handle bus errors to prevent lockup if (I2C_GetITStatus(I2C1, I2C_IT_BERR) != RESET) { I2C_ClearITPendingBit(I2C1, I2C_IT_BERR); } }
4. Your Question About Peripheral Activation
To answer your final question: Yes, enabling the PE bit via I2C_Cmd(I2C1, ENABLE) is all you need to start the I2C slave. Once enabled, the peripheral automatically monitors the bus for its address and sends an ACK on a match—assuming all hardware and configuration is correct.
Quick Hardware Checks
After fixing the pin mapping, confirm these hardware details:
- Add proper pull-up resistors (4.7kΩ to 10kΩ) between SDA/SCL and VCC if your FT2232H’s internal pull-ups aren’t sufficient.
- Verify no short circuits on SDA/SCL lines, and physical connections between FT2232H and STM32 are correct.
内容的提问来源于stack exchange,提问作者Mischa Binder

