Rath-HAL - 驱动板载 LED 闪烁

器材

  • 1x Tequila Nano + RA_LINK 调试器

电路连接

不需要进行额外连线

原理

Tequila Nano 的 PA2 针脚上连接板上自带的蓝色 LED 灯。LED 为 开漏连接,一端连接 3V3 电源,另一端连到 PA2 引脚,因此我们可以通过 GPIO 的开漏或推挽模式进行控制

Tequila Nano 上的蓝色 LED

代码

/**C
 * @file main.c
 * @version 1.0
 * @date 2021-07-27
 * 
 * The onboard LED for RATH Tequila Nano is connected to PA2, with the other end connected to 
 * 3V3. Thus, pulling the pin to LOW will turn on the LED, while pulling the pin to HIGH will
 * turn off the LED.
 * 
 */

#include "rath_hal.h"

static void AG_RCU_init(void);
static void AG_GPIO_init(void);

int main(void) {
  AG_RCU_init();
  AG_GPIO_init();

  while (1) {
    /* set the pin to output low voltage, thus turn ON the LED */
    HAL_GPIO_writePin(GPIOA, GPIO_PIN_2, LOW);
    
    /* delay for 0.1 second */
    HAL_delay(100);

    /* set the pin to output high voltage, thus turn OFF the LED */
    HAL_GPIO_writePin(GPIOA, GPIO_PIN_2, HIGH);

    /* delay for 0.1 second */
    HAL_delay(100);
  }
}

static void AG_RCU_init(void) {
  HAL_RCU_resetPeriphClock(RCU_GPIOA);

  HAL_RCU_enablePeriphClock(RCU_GPIOA);
}

static void AG_GPIO_init(void) {
  GPIO_InitTypeDef GPIO_init;
  
  /* configure PA2 as output open drain */
  GPIO_init.pin = GPIO_PIN_2;
  GPIO_init.mode = GPIO_MODE_OUTPUT_OD;
  GPIO_init.speed = GPIO_SPEED_50MHZ;
  GPIO_init.pull = GPIO_PULL_NONE;
  HAL_GPIO_init(GPIOA, &GPIO_init);
}

你可能感兴趣的:(Rath-HAL - 驱动板载 LED 闪烁)