2008-03-24 09:31 PM
Port inside GPIO
2011-05-17 03:26 AM
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, MJ2011-05-17 03:26 AM
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).2011-05-17 03:26 AM
write 0x00FF to GPIOx_ODR.
2011-05-17 03:26 AM
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 ]2011-05-17 03:26 AM
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 ]2011-05-17 03:26 AM
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.
2011-05-17 03:26 AM
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.2011-05-17 03:26 AM
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 ]2011-05-17 03:26 AM
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.