Skip to main content
gdiez
Associate III
Oct 13, 2010 7:56 AM UTC
Question

ALTERNATE FUNCTION CONFUSION

Posted on October 13, 2010 at 09:56

ALTERNATE FUNCTION CONFUSION

    This topic has been closed for replies.

    6 replies

    js23
    Associate III
    May 17, 2011 12:11 PM UTC
    Posted on May 17, 2011 at 14:11

    1.- how does the micro

    distinguish I2C1_SCL and USART_TX

    1.

     

     

    The peripherial that is enabled takes control over the pins. Simply do not enable another peripherial on the same pins.

    2.- And if my I2C_SCL and I2C_SDA pins are PB8 and PB9, how must I configure it??

    You will have to remap the I2C1 pins to PB8/9:

      GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);

    js23
    Associate III
    May 17, 2011 12:11 PM UTC
    Posted on May 17, 2011 at 14:11

    If you want to use a port pin for alternate function, you

    always

    have to configure it:

    * For peripherial outputs (like Usart TX, SPI CLK)  normally AF_PP or AF_OD must be used. This disconnects the pin driver from the GPIO and connects it to the peripherial

    * For inputs (e.g. RX, SPI MISO) normally IN_FLOATING, sometimes IPU/IPD is required. (BTW: This means that reading the state of the GPIO pin is still possible)

    Chapter 8.1.11 in the Useguide shows the configuration for every peripherial. (you will find I2C listed with AF_OD there)

    With remapping, you simply route the peripherial lines to another port. Sometimes you have more than one choice. CAN is initially found on PA11/12 and might go to PB8/9 or PD0/1 when remapped. This is the reason why GPIO_Remap1_CAN (for PB8/9) and GPIO_Remap2_CAN (for PD0/1) exist.

    And to make things even more complicated, some peripherials can be partially remapped...
    gdiez
    gdiezAuthor
    Associate III
    May 17, 2011 12:11 PM UTC
    Posted on May 17, 2011 at 14:11

    /*******************************************************************************

    * Function Name  : GPIO_PinRemapConfig

    * Description    : Changes the mapping of the specified pin.

    * Input          : - GPIO_Remap: selects the pin to remap.

    *                    This parameter can be one of the following values:

    *                       - GPIO_Remap_SPI1

    *                       - GPIO_Remap_I2C1

    *                       - GPIO_Remap_USART1

    *                       - GPIO_Remap_USART2

    *                       - GPIO_PartialRemap_USART3

    *                       - GPIO_FullRemap_USART3

    *                       - GPIO_PartialRemap_TIM1

    *                       - GPIO_FullRemap_TIM1

    *                       - GPIO_PartialRemap1_TIM2

    *                       - GPIO_PartialRemap2_TIM2

    *                       - GPIO_FullRemap_TIM2

    *                       - GPIO_PartialRemap_TIM3

    *                       - GPIO_FullRemap_TIM3

    *                       - GPIO_Remap_TIM4

    *                       - GPIO_Remap1_CAN

    *                       - GPIO_Remap2_CAN

    *                       - GPIO_Remap_PD01

    *                       - GPIO_Remap_TIM5CH4_LSI

    *                       - GPIO_Remap_ADC1_ETRGINJ

    *                       - GPIO_Remap_ADC1_ETRGREG

    *                       - GPIO_Remap_ADC2_ETRGINJ

    *                       - GPIO_Remap_ADC2_ETRGREG

    *                       - GPIO_Remap_SWJ_NoJTRST

    *                       - GPIO_Remap_SWJ_JTAGDisable

    *                       - GPIO_Remap_SWJ_Disable

    *                  - NewState: new state of the port pin remapping.

    *                    This parameter can be: ENABLE or DISABLE.

    * Output         : None

    * Return         : None

    *******************************************************************************/

    So to use the remap colum of one pin we must do:

    GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);

    and only with that the pins PB8 and PB9 gets configured??

    Must we configure the pin PB8 and PB9 like alternate function??

    So to configure:

    PB8 = I2C1_SCL

    PB9 = I2C1_SDA

    PD0 = CAN_RX

    PD1 = CAN_TX

    PB1 = ADC12_IN9

    Is the following code correct?

    ONLY PINS CONFIGURATION

     

     

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

     

    /*--------------------------------------------------------------------------------- PD.0 / PD.1-------- */

    GPIO_PinRemapConfig(GPIO_Remap1_CAN,ENABLE); // THAT OR THE FOLLOWING?

    GPIO_PinRemapConfig(GPIO_Remap2_CAN,ENABLE);

    /* --- Configure CAN pin: RX ---------------- */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

      GPIO_Init(GPIOD, &GPIO_InitStructure);

     

    /* --- Configure CAN pin: TX ---------------- */

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

      GPIO_Init(GPIOD, &GPIO_InitStructure);

     

    /*--------------------------------------------------------------------------------- PB.0 / PB.09 -------- */

    GPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);

     GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8 | GPIO_Pin_9;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

      GPIO_Init(GPIOB, &GPIO_InitStructure);

    /*----------------------------------------------------------------------------------------------- PB.01 ----- */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;           /* PB.01 ADC CHANNEL 9 */

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;       /* ANALOG INPUT */

      GPIO_Init(GPIOC, &GPIO_InitStructure);

    /*--------------------------------------------------------------------------------------------------------------- */

    FOLLOW THE NEXT FIGURE

    0690X00000602i9QAA.jpg

    mehmet.karakaya
    Associate III
    May 17, 2011 12:11 PM UTC
    Posted on May 17, 2011 at 14:11

    this remapping confuses me much too

    compare with TMS320F2000 from Texas Instruments

    only one alternate function is enabled at the port pin at the same time 

    even if 2 peripherals are enabled at the same time or not

    js23
    Associate III
    May 17, 2011 12:11 PM UTC
    Posted on May 17, 2011 at 14:11

    Ups, the word ''Userguide'' is wrong here... worked a little bit too much with TI controllers in the past. It should be ''Reference Manual'' (RM0008 

    http://www.st.com/stonline/products/literature/rm/13902.pdf

     )

    gdiez
    gdiezAuthor
    Associate III
    May 17, 2011 12:11 PM UTC
    Posted on May 17, 2011 at 14:11

    Hi and thaks for the quick reply. I´m so glad for oyur help. Can you tell me what document is Userguide?

    I´ve Hitex insider´s guide, RM0008 and the datasheet.

    Can you give me the link to this document?