Skip to main content
mj_it
Associate III
March 25, 2008
Question

Port inside GPIO

  • March 25, 2008
  • 12 replies
  • 2429 views
Posted on March 25, 2008 at 05:31

Port inside GPIO

    This topic has been closed for replies.

    12 replies

    mj_it
    mj_itAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    Hello!

    I would like to know if any of you can help me...

    I want to use 8bits from a GPIO port (not consecutive) as a common port for a LCD display of 16x1 chars. I know how to use individual pins, but how can I do with all at the same time?

    Any idea?

    Thank you,

    MJ

    bob239955
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    write 0x00FF to GPIOx_ODR.

    lanchon
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    you can set and clear specific bits of the GPIOx port simultaneously with a single write of the GPIOx_BSRR register.

    if you need max speed and your bits are all scrambled, you can use a precomputed 256-word look-up table (1KB code space).

    lanchon
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    the idea of using BSRR is that you can set or reset many bits at the same time. if you want to set one bit at a time you can just use the bitband area.

    janis
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    You can write macro like this:

    #define LCD(x) GPIOA->BSRR |= (x & 0x1 ? GPIO_Pin_0 : GPIO_Pin_0 << 16);

    GPIOA->BSRR |= (x & 0x2 ? GPIO_Pin_1 : GPIO_Pin_1 << 16);

    .

    GPIOA->BSRR |= (x & 0x8 ? GPIO_Pin_7 : GPIO_Pin_7 << 16);

    And you can also predefine ports and pins so you can change them fast if you need.

    [ This message was edited by: janis.skujenieks on 19-03-2008 09:04 ]

    mj_it
    mj_itAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    Thank you for your answers, but for example, what I don't really know is how I can write data (a variable) from the STM32 port to the display one.

    I want something like this:

    #define PORT (Pin_7 | ... | Pin_0)

    and then,

    Data = PORT

    [ This message was edited by: mj1 on 18-03-2008 11:45 ]

    janis
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    Quote:

    It seems the LCD() macro only sets bits in BSRR by oring, so eventually all BSRR bits may stay set

    No, the upper 16 bits of BSRR register resets appropriate port pins, so if you look at the macro - if evaluated false it shifts GPIO_Pin_x left by 16 thus reseting it.

    bob239955
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    you can set and reset bits at the same time by writing to ODR. All bits.

    By writing to BSRR you can leave some bits unchanged. Much better here.

    It seems the LCD() macro only sets bits in BSRR by oring, so eventually all BSRR bits may stay set.

    [ This message was edited by: bobz on 20-03-2008 18:38 ]

    ericvanolden9
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    I think faster méthod to write 8 bits in a port is to write ODR register.

    I use this method in a design and I do only a write in ODR (no read, modify, write). This is ok if you know that when yiu design your board. In a port you use only Px0 to Px7 for the bus of the Lcd and Px8 to Px15 are use as input. Inputs must be configured in High-Z mode, else writing to ODR enable pull-up or pull-down. With this method, Px8 to Px15 are fully functionnal. Bits 8-15 in ODR are don't care.

    bob239955
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 12:26

    Hi Janis:-), actually because you unnecessarily used |= operator (for the write only BSRR register) I was hinting that all the bits would get set if the |= operator had been necessary.

    You only need use the assignment operator =

    The BSRR register always reads as 0

    Best regards:-D

    [ This message was edited by: bobz on 20-03-2008 13:23 ]