Toggling a Port Pin on MK20DN64

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggling a Port Pin on MK20DN64

736 Views
ryan_pearson
Contributor III

I made a KDS project for the MK20DN64 using Processor Expert.  I'm simply trying to configure PTD4/LLWU_P14 as a GPIO and toggle the pin.  I am able to debug the project, but I do not see the pin being driven.  The pin just floats.  What is missing?  I'm using GPIO_PDD_SetPortOutputDirectionMask and GPIO_PDD_SetPortDataOutput.  Here is my main function:

int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
long int test;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */
/* For example: for(;;) { } */
GPIO_PDD_SetPortOutputDirectionMask((GPIO_MemMapPtr)0x4004C000u, 0x4000);
GPIO_PDD_SetPortDataOutput((GPIO_MemMapPtr)0x4004C000u, 0x4000);
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

4 Replies

606 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Ryan Pearson,

Please try the codes show below:

  /* Enable clock gate for ports to enable pin routing */
  SIM_PDD_SetClockGate(SIM_BASE_PTR, SIM_PDD_CLOCK_GATE_PORTD, PDD_ENABLE);

  /* Configure pin as output */
  GPIO_PDD_SetPortDirection(PTA_BASE_PTRPTD_BASE_PTR,GPIO_PDD_PIN_4);
  /* Set initialization value */
  GPIO_PDD_SetPortDataOutput(PTA_BASE_PTRPTD_BASE_PTR, GPIO_PDD_PIN_4);

  /* Initialization of Port Control register */
  PORT_PDD_SetPinMuxControl(PORTD_BASE_PTR, 4, PORT_PDD_MUX_CONTROL_ALT1);

  /* Toggle the output of PTD4 */
  GPIO_PDD_TogglePortDataOutputMask(PTA_BASE_PTRPTD_BASE_PTR,GPIO_PDD_PIN_4);

You can also use other components, for example: BitIO_LDD

BitIO_LDD PTD4.png

Help on Component.png

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

606 Views
ryan_pearson
Contributor III

Thanks Robin!  It worked after I changed "PTA_BASE_PTR" to "PTD_BASE_PTR".

606 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Thanks for reminding!

fixed

0 Kudos

606 Views
mjbcswitzerland
Specialist V

Hi

There could be two things going wrong:

- PTD4 is disabled by default and so needs to be configured to a GPIO function (with specific drive current and slew rate characteristics) before it can be used (its clocks also need to be enabled to it but I assume that the project generate just enables all port clocks as default somewhere)

- PTD4 is probably referenced to as 0x0010 and not 0x4000

If you want to do it easier and more efficiently download the uTasker project from GITHUB which has a K20DN target and allows you to simulate the chip (to avoid needing to debug on the target).
To configure the port and drive it to '1' you just do

_CONFIG_DRIVE_PORT_OUTPUT_VALUE(D, (PORTD_BIT4), (PORTD_BIT4), (PORT_SRE_SLOW | PORT_DSE_HIGH));

The port macros (compatible across all parts) are here:
http://www.utasker.com/forum/index.php?topic=1875.0

Regards

Mark

0 Kudos