应用库第二弹:uart
串口通信大家肯定很熟悉了,但是linux上串口大家一定用的比较少吧,大多人在mpu的板子都是做一些数据处理,opencv之类的,都比较高大上。
写这一系列库就是可以让mpu板子和stm32一样玩;
程序主函数:
1) 先初始化了串口
串口通信大家肯定很熟悉了,但是linux上串口大家一定用的比较少吧,大多人在mpu的板子都是做一些数据处理,opencv之类的,都比较高大上。
写这一系列库就是可以让mpu板子和stm32一样玩;
程序主函数:
int main(int argc, char** argv)
{
int dev_fd;
if ((dev_fd = uart_init()) == -1) {
printf("uart_init error\n");
return -1;
}
unsigned char data = 0;
uart_send_buf(dev_fd, (unsigned char*)mesg_buf, strlen(mesg_buf));
while (1) {
if (uart_get_char(dev_fd, &data) > 0)
uart_send_char(dev_fd, data);
sleep(1);
uart_send_char(dev_fd, 'C');
}
uart_deinit(dev_fd);
return 0;
}