cancel
Showing results for 
Search instead for 
Did you mean: 

Communicate with I2C a STM32 and a Raspberry

Mvega
Associate II

I want to connect a Raspberry Pi and a STM32F446 via I2C. I want the STM to be the slave. The code on the Raspberry is ok because I am already connected to other devices but when i search for the adress of the STM it doesn't appear. I'm sure the problem is with the init bu can't find it. I attach the code of the init.

Thanks in advance.

void I2C_Init(void){

GPIO_InitTypeDef GPIO_InitStruct;

I2C_InitTypeDef I2C_InitStruct;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_Init(GPIOC, &GPIO_InitStruct);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_I2C3); //SCL

GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_I2C3); //SDA

I2C_InitStruct.I2C_Mode = I2C_Mode_SMBusDevice;

I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;

I2C_InitStruct.I2C_OwnAddress1 = 0x10;

I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;

I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

I2C_InitStruct.I2C_ClockSpeed = 100000;

I2C_DeInit(I2C3);

I2C_Init(I2C3, &I2C_InitStruct);

I2C_Cmd(I2C3, ENABLE);

}

4 REPLIES 4
S.Ma
Principal

It might be easier to implement SPI link between both devices, and bit rate should easily be 12 mbps or higher.

Mvega
Associate II

I know but for my case i can only use I2C...

Mvega
Associate II

solved

I'm also struggling with connecting STM32 to RPi as a slave. Could you please share you solution?