hi,
i am working on TRK KEA128 GPIOs, i was able to work with the user buttons (that were on pins PTD0 and PTD1) that were on the board and also by connecting my external switches on to PTD0 and PTD1. Once i started configuring the other GPIO dedicated pins( to be specific PTE7,PTH0 and PTH1), i couldnt read the pin status! Am i missing anything here ??
This is what I am using to configure and enable the pins to be input .
CONFIG_PIN_AS_GPIO(D,PTD0,INPUT); /* Configure SW1 (PTD0) as an input */
CONFIG_PIN_AS_GPIO(D,PTD1,INPUT); /* Configure SW2 (PTD1) as an input */
CONFIG_PIN_AS_GPIO(E,PTE7,INPUT); /* Configure PTE7 as an input from external switch */
CONFIG_PIN_AS_GPIO(H,PTH0,INPUT); /* Configure PTH0 as an input from external switch */
CONFIG_PIN_AS_GPIO(H,PTH1,INPUT); /* Configure PTH1 as an input from external switch */
ENABLE_INPUT(D,PTD0);
ENABLE_INPUT(D,PTD1);
ENABLE_INPUT(E,PTE7);
ENABLE_INPUT(H,PTH0);
ENABLE_INPUT(H,PTH1);
and check status by,
if( (GPIOA_PDIR & GPIO_PDIR_PDI(0x1000000)) >> 24){
LED3_OFF;
}else{
LED3_ON;
}
if( (GPIOA_PDIR & GPIO_PDIR_PDI(0x2000000)) >> 25){
LED2_OFF;
}else{
LED2_ON;
}
if( (GPIOB_PDIR & GPIO_PDIR_PDI(0x80)) >> 7){
LED1_OFF;
}else{
LED1_ON;
}
this is how (Fig 1) i have connected to external switch !
Fig 1
Solved! Go to Solution.
Hi Jashan,
There is a bug (programming bug) on GPIO.h,
if you look at GPIO.h where all port numbers are associated with its respective GPIO port:
#define A A
#define B A
#define C A
#define D A
#define E B
#define F B
#define G B
#define H B
#define I C
Then, if you call CONFIG_PIN_AS_GPIO(port,port_pin,mode), using previous defines, it should look like:
CONFIG_PIN_AS_GPIO(port,port_pin,mode) ->
(mode == 0) ? (GPIO##port##_PDDR |= 0 << port_pin) : (GPIO##port##_PDDR |= 1 << port_pin)
For example:
CONFIG_PIN_AS_GPIO(A, PTA0,OUTPUT) ->
(1 == 0) ? (GPIOA_PDDR |= 0 << 0) : (GPIOA_PDDR |= 1 << 0)
In this case, GPIO##port##_PDDR is replaced by GPIOA_PDDR due #define A A macro.
But what happen when trying to configure port B (or PORT C) pins, for example PTE0 :
CONFIG_PIN_AS_GPIO(E, PTE0,OUTPUT) ->
(1 == 0) ? (GPIOB_PDDR |= 0 << 0) : (GPIOB_PDDR |= 1 << 0)
But if you see preprocessor’s output (right click over main.c and select Preprocess) you will notice that macro is replaced by:
CONFIG_PIN_AS_GPIO(E, PTE0,OUTPUT) ->
(1 == 0) ? (GPIOA_PDDR |= 0 << 0) : (GPIOA_PDDR |= 1 << 0)
But, why this is happening?, it should be GPIOB instead GPIOA, if you analyze next macro:
#define E B
Preprocessor replaced letter E by B, but,
#define B A
Then, B is replaced by letter A, resulting ALWAYS (no matter port number: A,B,C, ..I) in writing to GPIOA registers.
How can I fix this issue? Easy!! Due Preprocessor instructions are case-sensitive; you can change macros as follow:
#define a A
#define b A
#define c A
#define d A
#define e B
#define f B
#define g B
#define h B
#define i C
So in this case, when referring to PORT number, we use lower-case letter, so preprocessor makes substitution correctly:
CONFIG_PIN_AS_GPIO(e, PTE0,OUTPUT) ->
(1 == 0) ? (GPIOB_PDDR |= 0 << 0) : (GPIOB_PDDR |= 1 << 0)
After changing this macros and calling them using lower case port numbers there must be no errors.
I attach a project where these changes are implemented and you can notice how all port pins are working correctly.
Regards,
Isaac Avila
Hi Jashan,
There is a bug (programming bug) on GPIO.h,
if you look at GPIO.h where all port numbers are associated with its respective GPIO port:
#define A A
#define B A
#define C A
#define D A
#define E B
#define F B
#define G B
#define H B
#define I C
Then, if you call CONFIG_PIN_AS_GPIO(port,port_pin,mode), using previous defines, it should look like:
CONFIG_PIN_AS_GPIO(port,port_pin,mode) ->
(mode == 0) ? (GPIO##port##_PDDR |= 0 << port_pin) : (GPIO##port##_PDDR |= 1 << port_pin)
For example:
CONFIG_PIN_AS_GPIO(A, PTA0,OUTPUT) ->
(1 == 0) ? (GPIOA_PDDR |= 0 << 0) : (GPIOA_PDDR |= 1 << 0)
In this case, GPIO##port##_PDDR is replaced by GPIOA_PDDR due #define A A macro.
But what happen when trying to configure port B (or PORT C) pins, for example PTE0 :
CONFIG_PIN_AS_GPIO(E, PTE0,OUTPUT) ->
(1 == 0) ? (GPIOB_PDDR |= 0 << 0) : (GPIOB_PDDR |= 1 << 0)
But if you see preprocessor’s output (right click over main.c and select Preprocess) you will notice that macro is replaced by:
CONFIG_PIN_AS_GPIO(E, PTE0,OUTPUT) ->
(1 == 0) ? (GPIOA_PDDR |= 0 << 0) : (GPIOA_PDDR |= 1 << 0)
But, why this is happening?, it should be GPIOB instead GPIOA, if you analyze next macro:
#define E B
Preprocessor replaced letter E by B, but,
#define B A
Then, B is replaced by letter A, resulting ALWAYS (no matter port number: A,B,C, ..I) in writing to GPIOA registers.
How can I fix this issue? Easy!! Due Preprocessor instructions are case-sensitive; you can change macros as follow:
#define a A
#define b A
#define c A
#define d A
#define e B
#define f B
#define g B
#define h B
#define i C
So in this case, when referring to PORT number, we use lower-case letter, so preprocessor makes substitution correctly:
CONFIG_PIN_AS_GPIO(e, PTE0,OUTPUT) ->
(1 == 0) ? (GPIOB_PDDR |= 0 << 0) : (GPIOB_PDDR |= 1 << 0)
After changing this macros and calling them using lower case port numbers there must be no errors.
I attach a project where these changes are implemented and you can notice how all port pins are working correctly.
Regards,
Isaac Avila
hi Issac Avila,
All the GPIOs which i had connected and configured are working properly now after making changes as suggested.Thank you for the help!
Regards,
Jashan M