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 */
CLOCK_EnableClock(kCLOCK_PortA);
/* Port C Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);

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 */
PORT_SetPinMux(BOARD_TestIn_PORT, BOARD_TestIn_PIN, kPORT_MuxAsGpio);

/* 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. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
/* Init FSL debug console. */
BOARD_InitDebugConsole();

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. */

TestOut_ON();
TestOut_OFF();

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.

#

Outcomes