stm32与树莓派运用wiringPi.h 进行串口通信

由于需要运用树莓派算出座标 再传输给单片机 所以两者之间进行串口通信

参考资料 http://www.cnblogs.com/uestc-mm/p/7204429.html

https://www.cnblogs.com/lulipro/p/5992172.html

本人使用QT   注意  在.pro 加入LIBS += -lwiringPi 

#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <wiringPi.h>
#include <wiringSerial.h>

int main(int argc, char *argv[])
{
    int fd;
    if ((fd = serialOpen("/dev/ttyAMA0", 115200)) < 0)
    {
        fprintf(stderr, "Unable to open serial device: %s\n", strerror(errno));
        return 1 ;
    }

        serialPuts(fd, "100 50 100\r\n");

     delay(1000);




    for (;;)
    {
        if (serialDataAvail(fd) > 0)
        {
            putchar(serialGetchar(fd));
        }
    }
    return 0;
}

由于通讯协议是正点原子的  说所以serialPuts(fd, "100 50 100\r\n");  要加\r\n 否则无法识别

连接图传不上来  就树莓派的io口接单片机的io口 接地就行了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章