cancel
Showing results for 
Search instead for 
Did you mean: 

Port inside GPIO

mj
Associate II
Posted on March 25, 2008 at 05:31

Port inside GPIO

12 REPLIES 12
mj
Associate II
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

lanchon
Associate III
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).

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

write 0x00FF to GPIOx_ODR.

mj
Associate II
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
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 ]

lanchon
Associate III
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.

ericvanolden9
Associate II
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 II
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 ]

janis
Associate II
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.