cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4xx I2C slave not working

MBind.1
Associate

I'm currently trying to setup a STM32F4DISCOVERY Board with the STM32F407VGT6 chip as a I2C slave. Somehow the controller doesn't send any ACK bit after the address was received. I've tried with the General Call function as well.

Here is my initialisation of the I2C slave:

GPIO_InitTypeDef gpio_init;
		I2C_InitTypeDef i2c_init;
		
		RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
		
		gpio_init.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8;
		gpio_init.GPIO_Mode = GPIO_Mode_AF;
		gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
		gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;
		gpio_init.GPIO_OType = GPIO_OType_OD;
		GPIO_Init(GPIOB, &gpio_init);
		
		GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
		GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_I2C1);
		
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
		
		I2C_DeInit(I2C1);
		I2C_SoftwareResetCmd(I2C1, ENABLE);
		I2C_SoftwareResetCmd(I2C1, DISABLE);
		i2c_init.I2C_ClockSpeed = 50000;
		i2c_init.I2C_Mode = I2C_Mode_I2C;
		i2c_init.I2C_DutyCycle = I2C_DutyCycle_2;
		i2c_init.I2C_OwnAddress1 = 0x42;
		i2c_init.I2C_Ack = I2C_Ack_Enable;
		i2c_init.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
		I2C_Init(I2C1, &i2c_init);
		
		I2C_ITConfig(I2C1, I2C_IT_ERR, ENABLE);
		I2C_ITConfig(I2C1, I2C_IT_EVT, ENABLE);
		I2C_ITConfig(I2C1, I2C_IT_BUF, ENABLE);
		NVIC_InitTypeDef NVIC_InitStructure;
		
		NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQn;
		NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
		NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
		NVIC_Init(&NVIC_InitStructure);
		I2C_StretchClockCmd(I2C1, ENABLE);
		I2C_Cmd(I2C1, ENABLE);
		
		I2C_GeneralCallCmd(I2C1, ENABLE);

The data is correctly on the SCL and SDA pins. So thats not the problem. Thanks =)

1 REPLY 1
MBind.1
Associate

Using the I2C2 module instead did not affect the result. Same. No Acknowledge bit