实际使用中,我们会用到UART发送和接收处理,这里以simple为示例,介绍UART0和1的接收发送示例 1)定义端口 #define PIN_WAKEUP_0 14 // UART-RTS@EVB #define PIN_WAKEUP_1 24 // KEY1@EVB #define PIN_LED_0 12 #define PIN_LED_1 11 #define PIN_LED_2 23 #define PIN_LED_3 2 #define PIN_LED_4 13 #define PIN_LED_5 14 #define PIN_LED_6 14 #define PIN_LED_7 14 #define PIN_UART0_TX 5 #define PIN_UART0_RX 6 #define PIN_UART1_TX 15 // 9 #define PIN_UART1_RX 16 // 10 #define DBG_SWDIAG_IO_RVS 0x80 #define HCI_UART_BAUDRATE 115200 #define DEBUG_UART_BAUDRATE 115200 2)定义UART口配置 static void pinmux_init(void) { // KEY pinmux_config(PIN_WAKEUP_0, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_WAKEUP_1, PINMUX_GPIO_MODE_CFG); pmu_pin_mode_set(pin_wakeup_mask, PMU_PIN_MODE_PU); // UART0 pinmux_config(PIN_UART0_TX, PINMUX_UART0_SDA_O_CFG); pinmux_config(PIN_UART0_RX, PINMUX_UART0_SDA_I_CFG); pmu_pin_mode_set(BITMASK(PIN_UART0_TX), PMU_PIN_MODE_PP); pmu_pin_mode_set(BITMASK(PIN_UART0_RX), PMU_PIN_MODE_PU); // UART1 pinmux_config(PIN_UART1_TX, PINMUX_UART1_SDA_O_CFG); pinmux_config(PIN_UART1_RX, PINMUX_UART1_SDA_I_CFG); pmu_pin_mode_set(BITMASK(PIN_UART1_TX), PMU_PIN_MODE_PP); pmu_pin_mode_set(BITMASK(PIN_UART1_RX), PMU_PIN_MODE_PU); // LEDS pinmux_config(PIN_LED_0, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_1, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_2, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_3, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_4, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_5, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_6, PINMUX_GPIO_MODE_CFG); pinmux_config(PIN_LED_7, PINMUX_GPIO_MODE_CFG); pmu_pin_mode_set(pin_leds_mask, PMU_PIN_MODE_PP); } 3)打开UART static void peripheral_init(void) { // Init GPIO gpio_open(); // Wakeup Pin gpio_set_direction(pin_wakeup_mask, GPIO_INPUT); gpio_set_interrupt(pin_wakeup_mask, GPIO_BOTH_EDGE); gpio_set_interrupt_callback(gpio_handler); // LEDS gpio_write(pin_leds_mask, GPIO_HIGH); gpio_set_direction(pin_leds_mask, GPIO_OUTPUT); // wakeup pmu_wakeup_pin_set(pin_wakeup_mask, PMU_PIN_WAKEUP_LOW_LEVEL); pmu_wakeup_pin_register_callback(wakeup_gpio_handler, wakeup_gpio_handler); // Init UART uart_open(HS_UART0, DEBUG_UART_BAUDRATE, UART_FLOW_CTRL_DISABLED, uart0_receive_handler); uart_open(HS_UART1, DEBUG_UART_BAUDRATE, UART_FLOW_CTRL_DISABLED, uart1_receive_handler); } 4) 在睡眠唤醒后的函数中再开启一次UART static void peripheral_restore(void) { // Init UART uart_open(HS_UART0, DEBUG_UART_BAUDRATE, UART_FLOW_CTRL_DISABLED, uart0_receive_handler); uart_open(HS_UART1, DEBUG_UART_BAUDRATE, UART_FLOW_CTRL_DISABLED, uart1_receive_handler); } 5)在main.c中增加回调函数内容 void uart0_receive_handler(uint8_t data) { // Get data uint8_t buf[2] = {0x01,0x02}; uart_send_block(HS_UART0, buf, 2);//UART0 发送2个字节 } void uart1_receive_handler(uint8_t data) { // Get data uint8_t buf[2] = {0x01,0x02}; uart_send_block(HS_UART1, buf, 2);//UART1 发送2个字节 } |