cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496 I2C1/3 cannot work on GPIOG port.

ray
Associate II
Posted on April 08, 2018 at 09:13

L496 port G includes two I2C- PG13/14 I2C1 and PG7/8 I2C3. But the two I2C cannot output and the oscilloscope does not display waveform.

I2C1/I2C3 can work correctly if they are mapped to other ports. So I think the I2C1/I2C3 modules are ok in L496.

On the other hand, if I set PG13/14 and PG7/8 pin mode as GPIO output, they can work well. So the GPIOG module is ok.

So what is the problem with GPIOG I2C? I know Port G[15:2] are independent from other ports. But I connect Vddio2 to Vdd in the test. Please see the code below.

Init Code:

LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG);

HAL_PWREx_EnableVddIO2();

LL_GPIO_SetPinMode(GPIOG, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE);

LL_GPIO_SetAFPin_0_7(GPIOG, LL_GPIO_PIN_13, LL_GPIO_AF_4);

LL_GPIO_SetPinSpeed(GPIOG, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_HIGH);

LL_GPIO_SetPinOutputType(GPIOG, LL_GPIO_PIN_13, LL_GPIO_OUTPUT_OPENDRAIN);

LL_GPIO_SetPinPull(GPIOG, LL_GPIO_PIN_13, LL_GPIO_PULL_UP);

LL_GPIO_SetPinMode(GPIOG, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE);

LL_GPIO_SetAFPin_0_7(GPIOG, LL_GPIO_PIN_14, LL_GPIO_AF_4);

LL_GPIO_SetPinSpeed(GPIOG, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_HIGH);

LL_GPIO_SetPinOutputType(GPIOG, LL_GPIO_PIN_14, LL_GPIO_OUTPUT_OPENDRAIN);

LL_GPIO_SetPinPull(GPIOG, LL_GPIO_PIN_14, LL_GPIO_PULL_UP);

Read Code:

LL_I2C_Enable(I2C1);

LL_I2C_HandleTransfer(I2C1, add, LL_I2C_ADDRSLAVE_7BIT, 2, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_READ);

while (!LL_I2C_IsActiveFlag_STOP(I2C1))

{

if (LL_I2C_IsActiveFlag_RXNE(I2C1))

{

i2c1Ctx.rxBuffer[0] = LL_I2C_ReceiveData8(I2C1);

}

}

LL_I2C_ClearFlag_STOP(I2C1);
1 ACCEPTED SOLUTION

Accepted Solutions
Theo Hussey
Associate II
Posted on June 06, 2018 at 15:32

If you are setting a GPIO pin greater than 7 to an alternate function, you need to use the LL_GPIO_SetAFPin_8_15 function. eg.

LL_GPIO_SetAFPin_8_15(GPIOG,

LL_GPIO_PIN_13

, LL_GPIO_AF_4);

View solution in original post

5 REPLIES 5
Posted on April 08, 2018 at 16:41

Make sure the PWR peripheral's clock is enabled

LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);

You want code equivalent to

   /* VddIO2 must be enabled to access GPIO port G[2:15] */

   __HAL_RCC_PWR_CLK_ENABLE();

   HAL_PWREx_EnableVddIO2();

   __HAL_RCC_GPIOG_CLK_ENABLE();
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 12, 2018 at 12:27

Thanks Clive. I use HAL driver and it can work now. It would be some I2C setting problems in LL library. 

Actually I don't want to use HAL because it's too big and inefficient.  Thanks your help again.

Posted on April 12, 2018 at 17:33

Hi

Mei.Raymond

‌,

Could you please explain how you did resolved the issue with pins in port G to be used with I2C?

Thanks.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

ray
Associate II
Posted on April 13, 2018 at 02:57

I just used the demo in your Nucleo package,

STM32Cube_FW_L4_V1.10.0\Projects\STM32L496ZG-Nucleo\Examples\I2C\I2C_TwoBoards_ComPolling

I have not compared the detail difference in HAL and LL library for I2C setting. I think it is a bug to config Port G I2C1/3 in LL. Hope ST can fix it in the future. Thanks.

Theo Hussey
Associate II
Posted on June 06, 2018 at 15:32

If you are setting a GPIO pin greater than 7 to an alternate function, you need to use the LL_GPIO_SetAFPin_8_15 function. eg.

LL_GPIO_SetAFPin_8_15(GPIOG,

LL_GPIO_PIN_13

, LL_GPIO_AF_4);