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
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.
#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 ]
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.
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 ]
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.
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 ]