Author Topic: kinetis pin labels and blinky  (Read 1084 times)

0 Members and 1 Guest are viewing this topic.

Offline bennyTopic starter

  • Newbie
  • Posts: 6
  • Country: be
kinetis pin labels and blinky
« on: March 08, 2020, 03:51:33 pm »
Dear forum users

I have a question regarding mcuXpresso pin labels and a blinky.

1) what are the lables for ?(se the included picture)

2) and do I use the labels in the code below and how?

Sorry if it is a stupide question but it's my first time using the kinetis line of microcontrollers


Thank you in advance and with best regards Ben

<code>/* TODO: insert other definitions and declarations here. */
static void delay(volatile uint32_t nof) {
  while(nof!=0) {
    __asm("NOP");
    nof--;
  }
}

/*
 * @brief   Application entry point.
 */
int main(void) {
     /* Init board hardware. */
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();
    CLOCK_EnableClock(kCLOCK_PortC); /* enable clocks for port B */
    PORT_SetPinMux(PORTB, 9u, kPORT_MuxAsGpio);// setting pin PTB9 as an output
    /* Enter an infinite loop, just incrementing a counter. */
    while(1)
    {
       GPIO_PinWrite(GPIOB, 9u, 1<<9u);
       delay(1000);
       GPIO_PinWrite(GPIOB, 9u, 0<<9u);
    }
    return 0 ;
}
</code>
 

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 612
  • Country: es
Re: kinetis pin labels and blinky
« Reply #1 on: March 09, 2020, 07:57:00 am »

To write to your GPIO:
GPIO_PortSet  (BOARD_INITPINS_vibmotor_GPIO, 1U << BOARD_INITPINS_vibmotor_PIN); // ON
GPIO_PortClear(BOARD_INITPINS_vibmotor_GPIO, 1U << BOARD_INITPINS_vibmotor_PIN); // OFF

And if you need to read some GPIO
GPIO_PinRead(BOARD_INITPINS_label_GPIO, BOARD_INITPINS_label_PIN)


To write a more readable code or if you are going to use the same instruction several times in the program, you better assign it with a #define.

#define MOTOR_ON GPIO_PortSet  (BOARD_INITPINS_vibmotor_GPIO, 1U << BOARD_INITPINS_vibmotor_PIN);
#define MOTOR_OFF GPIO_PortClear(BOARD_INITPINS_vibmotor_GPIO, 1U << BOARD_INITPINS_vibmotor_PIN);


    while(1)
    {
       MOTOR_ON
       delay(1000);
       MOTOR_OFF
    }
« Last Edit: March 09, 2020, 08:06:20 am by luiHS »
 
The following users thanked this post: benny

Offline bennyTopic starter

  • Newbie
  • Posts: 6
  • Country: be
Re: kinetis pin labels and blinky
« Reply #2 on: March 09, 2020, 11:49:54 am »
Dear

That did trick thank you!


With best regards Ben
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->