love_electronic
Member level 5
Hi guys
I am using ARM controller and want to change the state of pin ( 0 or 1) which i assigned as OUTPUT.
The port output register in arm is GPIOx_PDOR which is 32bit.
where x is port A,B,C..etc
i have made a macro like
initially i high some pins by loading this value
Suppose i want to high pin 3 i set
then it will set PIN 3 HIGH with previously pins remain same, and it works fine. GPIOx_PDIR now has a value 0x06000084
when i set pin 3 to low
the code have no effect. GPIOx_PDIR has the same value 0x06000084; But what i required is 0x06000080
After analyzing the macro i conclude that OR operation is not changing the state of the pin
so i write 2 seperate macro's like that
when i load DATA_1(1) it works fine and when i load DATA_0(0) it also works fine
My Question is that can i write a single macro which perform both functions? like if receive 1 OUTPUT becomes HIGH and if receive 0 OUTPUT becomes LOW?
Also by using the 2nd macro i am restricted to change the state of only 3rd pin, if i want any other pin to go low i can't.
I am using ARM controller and want to change the state of pin ( 0 or 1) which i assigned as OUTPUT.
The port output register in arm is GPIOx_PDOR which is 32bit.
where x is port A,B,C..etc
i have made a macro like
Code:
#define DATA(x) GPIOB_PDOR |= (x<<2) & 0xFFFFFFFF
initially i high some pins by loading this value
Code:
GPIOx_PDOR = 0x06000080;
Code:
DATA(1)
when i set pin 3 to low
Code:
DATA(0)
After analyzing the macro i conclude that OR operation is not changing the state of the pin
so i write 2 seperate macro's like that
Code:
#define DATA_1(x) GPIOB_PDOR |= (x<<2) & 0xFFFFFFFF
#define DATA_0(x) GPIOB_PDOR &= (x<<2) | 0xFFFFFFF0
when i load DATA_1(1) it works fine and when i load DATA_0(0) it also works fine
My Question is that can i write a single macro which perform both functions? like if receive 1 OUTPUT becomes HIGH and if receive 0 OUTPUT becomes LOW?
Also by using the 2nd macro i am restricted to change the state of only 3rd pin, if i want any other pin to go low i can't.