cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4xx Standard Perhipheral Library's FMPI2C implementation not functional

PMcDo.3
Associate

I'm trying to implement I2C on pins PC6/7of the STM32F446RET, which as I understand can only be used in FMPI2C mode.

As such, I'm trying to use the Standard Peripheral Library since the rest of our codebase utilizes it and we do not currently include the full HAL driver library. Unfortunately, there's no documentation on this module of the library (the entire helpfile section on FMPI2C is blank) so I'm going in blind.

Here's what I've been doing so far as a simple test (just sending a sequence of bytes over the bus:

    // FMPI2C Configuration
    FMPI2C_InitTypeDef FMPI2C_InitStruct;
    //Enable the i2c
    RCC_APB1PeriphClockCmd(RCC_Per_FMPI2C, ENABLE);
    //Reset the Peripheral
    RCC_APB1PeriphResetCmd(RCC_Per_FMPI2C, ENABLE);
    RCC_APB1PeriphResetCmd(RCC_Per_FMPI2C, DISABLE);
  
    //Enable the GPIOs for the SCL/SDA Pins
    RCC_AHB1PeriphClockCmd(RCC_Per_SCL | RCC_Per_SDA, ENABLE);
 
    GPIO_InitStruct.GPIO_Pin = PIN_SCL;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStruct.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_Init(PORT_SCL, &GPIO_InitStruct);
 
    GPIO_InitStruct.GPIO_Pin = PIN_SDA;
    GPIO_Init(PORT_SDA, &GPIO_InitStruct);
    
    //Connect GPIO pins to peripheral
    GPIO_PinAFConfig(PORT_SCL, PINSRC_SCL, FMPI2C_AF);
    GPIO_PinAFConfig(PORT_SDA, PINSRC_SDA, FMPI2C_AF);
    
    //Configure and Initialize the I2C
    FMPI2C_InitStruct.FMPI2C_Timing = 0x00303D5B;
    FMPI2C_InitStruct.FMPI2C_AnalogFilter = FMPI2C_AnalogFilter_Enable;
    FMPI2C_InitStruct.FMPI2C_Mode = FMPI2C_Mode_FMPI2C;
    FMPI2C_InitStruct.FMPI2C_OwnAddress1 = 0x00; //We are the master. We don't need this
    FMPI2C_InitStruct.FMPI2C_Ack = FMPI2C_Ack_Enable;
    FMPI2C_InitStruct.FMPI2C_AcknowledgedAddress = FMPI2C_AcknowledgedAddress_7bit;
    
    //Initialize the Peripheral
    FMPI2C_Init(FMPI2C_Per, &FMPI2C_InitStruct);
    // I2C Peripheral Enable
    FMPI2C_Cmd(FMPI2C_Per, ENABLE);
 
    // I2C Test
    FMPI2C_GenerateSTART(FMPI2C_Per, ENABLE);
    FMPI2C_SendData(FMPI2C_Per, 0x01);
    FMPI2C_SendData(FMPI2C_Per, 0x02);
    FMPI2C_SendData(FMPI2C_Per, 0x03);
    FMPI2C_SendData(FMPI2C_Per, 0x04);
    FMPI2C_GenerateSTOP(FMPI2C_Per, ENABLE);

However this only results in a single byte of 0x00 appearing on the line, with nothing further:


_legacyfs_online_stmicro_images_0693W00000dDWdCQAW.pngNo matter what values I try to send, I only get the above result. I would appreciate any additional guidance to get this working. Thanks!

2 REPLIES 2
S.Ma
Principal

Maybe use the bitbang version, you will mostly need to rewrite the gpio portion and sw delay timings for the desired bit rate)

https://github.com/stm32-hotspot/STM32C0316-DK-Brisk-Demo/tree/main/Brisk

It is master mode only. This code has evolved over the years and works pretty damn well to jump you to your next task in your to do list.

Joe WILLIAMS
ST Employee

Hello PMcDo.3

Your question has been routed to the online support team. A case has been created and you'll be contacted shortly.

Kind Regards

ST Support