【东软载波ESF0654 PDS开发板活动】+串口通讯
1,考虑到板子上串口2和ES-LINKII的串口转USB有现成的连接:只要跳线就OK。
2,那就用这个接口。
3,接口IO为PD2 TX2 PC 12 RX2
4,采用例子ES-PDS-ES32F0654ES32_SDK_V1.04ProjectsES32F065xExamples_MDUART
5,修改如下:
main.h: #define UART2_TX_PORT GPIOC #define UART2_TX_PIN MD_GPIO_PIN_12 #define UART2_RX_PORT GPIOD #define UART2_RX_PIN MD_GPIO_PIN_2 main.c: md_uart_init_t init; uint8_t tx_buf[64]; uint8_t rx_buf[64]; void uart_pin_init(void) { md_gpio_init_t x; /* Initialize tx pin */ x.mode = GPIO_MODE_OUTPUT; x.odos = GPIO_PUSH_PULL; x.pupd = GPIO_PUSH_UP; x.odrv = GPIO_OUT_DRIVE_NORMAL; x.flt = GPIO_FILTER_DISABLE; x.type = GPIO_TYPE_TTL; x.func = GPIO_FUNC_5; md_gpio_init(UART2_TX_PORT, UART2_TX_PIN, &x); /* Initialize rx pin */ x.mode = GPIO_MODE_INPUT; x.odos = GPIO_PUSH_PULL; x.pupd = GPIO_PUSH_UP; x.odrv = GPIO_OUT_DRIVE_NORMAL; x.flt = GPIO_FILTER_DISABLE; x.type = GPIO_TYPE_TTL; x.func = GPIO_FUNC_5; md_gpio_init(UART2_RX_PORT, UART2_RX_PIN, &x); return; } /** * @brief Test main function * @retval Status. */ int main() { /* Initialize 1ms tick */ md_init_1ms_tick(); /* clear md_uart_init_t structure */ memset(&init, 0x0, sizeof(md_uart_init_t)); /* Initialize pin */ uart_pin_init(); /* Initialize tx_buf */ memset(tx_buf, 0x55, 32); /* Initialize UART */ init.baud = 115200; init.word_length = MD_UART_WORD_LENGTH_8B; init.stop_bits = MD_UART_STOP_BITS_1; init.parity = MD_UART_PARITY_NONE; init.fctl = MD_UART_FLOW_CTL_DISABLE; md_uart_init(UART2, &init); /* Send a message */ md_uart_send_data8(UART2, tx_buf[0]); /* Receive a message */ rx_buf[0] = (uint8_t)md_uart_recv_data8(UART2); while (1) { uint8_t index=0; if(index >=64) index =0; /* Send a message */ /* Receive a message */ rx_buf[index] = (uint8_t)md_uart_recv_data8(UART2); tx_buf[index]= rx_buf[index]; md_uart_send_data8(UART2, tx_buf[index]); index++; md_delay_1ms(1000); } }
6,串口调试助手:串口3 波特率115200 N81
7,编译运行,查看结果:
一周热门 更多>