AnsweredAssumed Answered

Using MCUXpresso Config Tools to specify input pin

Question asked by GANG FENG on Jun 18, 2018
Latest reply on Jun 19, 2018 by Alice_Yang

I am having trouble using the Pins Config Tools to make GPIO pin working in input mode.

The board I use is FRDM-K22F.

Here is what I did:

1) I created  a simple "Hello World" project by following the MCUXpresso_IDE_User_Guide.pdf.

2)  Use the Pins config tools to configure PTA4 as an input pin and PTC3 as an output pin. I gave am identifier 'TestIn' to PTA4, and 'TestOut' to PTC3.  The tools generated the following code in the  BOARD_initPins(void) (inside the pin_mux.h), which seem to be correct:


void BOARD_InitPins(void)
/* Port A Clock Gate Control: Clock enabled */
/* Port C Clock Gate Control: Clock enabled */

gpio_pin_config_t TestIn_config = {
.pinDirection = kGPIO_DigitalInput,
.outputLogic = 0U
/* Initialize GPIO functionality on pin PTA4 (pin 26) */
GPIO_PinInit(BOARD_TestIn_GPIO, BOARD_TestIn_PIN, &TestIn_config);

gpio_pin_config_t TestOut_config = {
.pinDirection = kGPIO_DigitalOutput,
.outputLogic = 0U
/* Initialize GPIO functionality on pin PTC3 (pin 46) */
GPIO_PinInit(BOARD_TestOut_GPIO, BOARD_TestOut_PIN, &TestOut_config);

/* PORTA4 (pin 26) is configured as PTA4 */

/* PORTC3 (pin 46) is configured as PTC3 */
PORT_SetPinMux(BOARD_TestOut_PORT, BOARD_TestOut_PIN, kPORT_MuxAsGpio);



2)   I added the following code to the board.h file:


#define TestOut_ON() \
GPIO_PortSet(BOARD_TestOut_GPIO, 1U << BOARD_TestOut_PIN) /*!< Set TestOut pin */
#define TestOut_OFF() \
GPIO_PortClear(BOARD_TestOut_GPIO, 1U << BOARD_TestOut_PIN) /*!< Clear TestOut pin */
#define Read_TestIn() \
GPIO_ReadPinInput(BOARD_TestIn_GPIO, 1U << BOARD_TestIn_PIN) /*!< Read TestIn pin */


3)  I added a few test lines in the main() procedure. The main() looks like this:


int main(void) {

uint32_t test_val;

/* Init board hardware. */
/* Init FSL debug console. */

PRINTF("Hello World\n");

/* Force the counter to be placed into memory. */
volatile static int i = 0 ;
/* Enter an infinite loop, just incrementing a counter. */


test_val = Read_TestIn();
PRINTF("input: %d\n",test_val);

while(1) {
i++ ;

return 0 ;


4) I compiled the project and stepped through the code using the debug mode.  Before running the code, I had PTA4 connected to a 3.3V input.  I can see the output pin PTC3 worked correctly by switching to HIGH and LOW as it stepped through the TestOut_ON() and TestOUT_OFF(), but when I stepped through the "test_val = Read_TestIn()", the test_val returned is always 0.    I tried to use different pins, but no success.  


If anyone see anything wrong I did, please leave a message.  Thank you very much for your help.