Skip to main content
Graduate
October 19, 2024
Solved

Why assign 4 pins for STM32746VGT I2C1

  • October 19, 2024
  • 2 replies
  • 4331 views

In attached datasheet  (it download from ST website) page 70-71 and 77-78, assign 4 pins to I2C1,

In CubeMX, it assign to B6,B7.

Is it typo?

    This topic has been closed for replies.
    Best answer by STTwo-32

    Hllo @Richard Li 

    Not exactly، i'm going to show you how to set each pin to I2C1 as alternate functions:

    For PB6, write 0 to the bit 12 of the GPIOB_MODER register and 1 to the bit 13 of the GPIOB_MODER register. After that, write 0 to the bits 24, 25 and 27 of the GPIOB_AFRL register and 1 to the bit 26 of the GPIOB_AFRL register.

    For PB7, write 0 to the bit 14 of the GPIOB_MODER register and 1 to the bit 15 of the GPIOB_MODER register. After that, write 0 to the bits 28, 29 and 31 of the GPIOB_AFRL register and 1 to the bit 30 of the GPIOB_AFRL register.

    For PB8, write 0 to the bit 16 of the GPIOB_MODER register and 1 to the bit 17 of the GPIOB_MODER register. After that, write 0 to the bits 0, 1 and 3 of the GPIOB_AFRH register and 1 to the bit 2 of the GPIOB_AFRH register.

    For PB9, write 0 to the bit 18 of the GPIOB_MODER register and 1 to the bit 19 of the GPIOB_MODER register. After that, write 0 to the bits 4, 5 and 7 of the GPIOB_AFRH register and 1 to the bit 6 of the GPIOB_AFRH register.

    GPIOB_MODER used to select the mode of the gpio (digital input, digital output, alternate function or analog). 

    GPIOB_AFRL used to select the alternate function of each of the pins PB0->PB7

    GPIOB_AFRH used to select the alternate function of each of the pins PB8->PB15.

    Please take a look at the GPIO chapter of the RM0385 For more details.

    Best Regards.

    STTwo-32 

     

    2 replies

    Technical Moderator
    October 19, 2024

    Hello @Richard Li 

    Infact, I2C1_SDA and I2C1_SCL are available on PB7, PB9 for the I2C1_SDA and PB6, PB8 for the I2C1_SCL. So, to use the I2C1, you can use any combination you want (PB6/PB7, PB6/PB9, PB8/PB7 and PB8/PB9) for example CubeMX use PB6/PB7 by default when they are available. But, if not or if you want to use one of the other pins, all you have to do is to go to the pin map on CubeMX and configure the other pins for I2C1. After that and once you enble i2c1, the pins that you have selected will be used instaid of the default ones.

    Best Regards.

    STTwo-32 

    Graduate
    October 19, 2024

    Hi, STTwo-32

    Do you know which register will set these pairs?

    For me, it should be AF register, check datasheet, these two pairs use same AF4 mode.

    Is it means same time, these two pairs available?

    I will try use F051 discovery board.

    I did check other ARM ip chip - cypress, it is same.

    Regards,

    Richard

    STTwo-32Answer
    Technical Moderator
    October 19, 2024

    Hllo @Richard Li 

    Not exactly، i'm going to show you how to set each pin to I2C1 as alternate functions:

    For PB6, write 0 to the bit 12 of the GPIOB_MODER register and 1 to the bit 13 of the GPIOB_MODER register. After that, write 0 to the bits 24, 25 and 27 of the GPIOB_AFRL register and 1 to the bit 26 of the GPIOB_AFRL register.

    For PB7, write 0 to the bit 14 of the GPIOB_MODER register and 1 to the bit 15 of the GPIOB_MODER register. After that, write 0 to the bits 28, 29 and 31 of the GPIOB_AFRL register and 1 to the bit 30 of the GPIOB_AFRL register.

    For PB8, write 0 to the bit 16 of the GPIOB_MODER register and 1 to the bit 17 of the GPIOB_MODER register. After that, write 0 to the bits 0, 1 and 3 of the GPIOB_AFRH register and 1 to the bit 2 of the GPIOB_AFRH register.

    For PB9, write 0 to the bit 18 of the GPIOB_MODER register and 1 to the bit 19 of the GPIOB_MODER register. After that, write 0 to the bits 4, 5 and 7 of the GPIOB_AFRH register and 1 to the bit 6 of the GPIOB_AFRH register.

    GPIOB_MODER used to select the mode of the gpio (digital input, digital output, alternate function or analog). 

    GPIOB_AFRL used to select the alternate function of each of the pins PB0->PB7

    GPIOB_AFRH used to select the alternate function of each of the pins PB8->PB15.

    Please take a look at the GPIO chapter of the RM0385 For more details.

    Best Regards.

    STTwo-32 

     

    Graduate
    October 19, 2024

    Thank you very much!