写k210通过串口通信方式向stm32发送数据的代码
时间: 2023-08-12 20:05:35 浏览: 76
以下是基于 Maixduino 开发板的 K210 与 STM32 通过串口通信方式发送数据的示例代码:
```c
#include <stdio.h>
#include <string.h>
#include "sysctl.h"
#include "plic.h"
#include "uart.h"
#define UART_NUM UART_DEVICE_3
#define UART_BUF_LEN 1024
uint8_t uart_buf[UART_BUF_LEN];
int main(void) {
sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL);
sysctl_pll_set_freq(SYSCTL_PLL1, 400000000UL);
uart_init(UART_NUM);
uart_configure(UART_NUM, 115200, UART_BITWIDTH_8BIT, UART_STOP_1, UART_PARITY_NONE);
uart_set_receive_trigger(UART_NUM, UART_RECEIVE_FIFO_1);
while (1) {
if (uart_receive_data(UART_NUM, uart_buf, UART_BUF_LEN) != 0) {
uart_send_data(UART_NUM, uart_buf, strlen((const char *)uart_buf));
}
}
}
```
以上代码实现了从串口接收数据并通过同一串口发送数据。你可以将该代码烧录到 K210 上,并将 K210 和 STM32 通过串口连接起来,然后在 STM32 上通过串口发送数据给 K210,K210 就会将收到的数据原样发送回去。