printf("nx=%d\n",nx);
while(1)
{
if((nread = read(fd,buff,512))>0)
{
buff[nread] = '\0';
//write(fd,buff,nread);
printf("\nrecv:%d\n",nread);
//printf("%s",buff);
printf("%d",buff[0] );
printf("%d",buff[1] );
printf("%d",buff[2] );
printf("%d",buff[3] );
printf("\n");
}
}
return 1;
}
搞个MakeFile
CC=arm-linux-gcc
SEND_EXEC=serial_send
all:serial_port.c serial_port.h serial_send_msg.c
$(CC) -o $(SEND_EXEC) serial_port.c serial_send_msg.c
#chmod 777 $(SEND_EXEC)
clean:
rm -rf *.o serial_send
哈哈,完成,接下来就是测试了。这里将电路板中的TXD2和RXD2短接,即自发自读,串口打印“Hi Babby!”嘿嘿,搞定。后面会搞一个GSM模块玩玩。也是串口