stm32 usart read
787562067
googcheng at qq.com
Fri Mar 22 08:01:49 UTC 2019
HI, ALL!
I am new to rtems. now write the usart application by usart3 (PD8 PD9 pin)
when i input a string "qqw" by port tool Hercules, i only get one char 'q' returned , so i think the read here is not
like the linux read function, i dont know how to handle it, hope you could give some hints!
code output log:
Serial port COM2 opened
*** Simple COM1 Test ***
Opened COM1, fd=3
Hello, I'm waiting for input..
wait 5s
*** Simple COM1 Test ***
Opened COM1, fd=3
Hello, I'm waiting for input..
wait 5s
*** Simple COM1 Test ***
Opened COM1, fd=3
Hello, I'm waiting for input..
wait 5s
*** Simple COM1 Test ***
Opened COM1, fd=3
Hello, I'm waiting for input..
wait 5s
qwwq
==================================
void testCom1(void);
void testCom1(void) {
char buffer[256] = {0};
printf("*** Simple COM1 Test ***\n");
//int fd = open("/dev/ttyS2", O_RDWR | O_NOCTTY | _FNDELAY);
int fd = open("/dev/ttyS2", O_RDWR | O_NOCTTY);
printf("\nOpened COM1, fd=%d\n\n", fd);
if(fd < 0)
printf("open error\n");
#if 0
if(fcntl(fd, F_SETFL, 0) < 0)
{
printf("fcntl failed!\n");
return;
}
else
{
printf("fcntl=%d\n",fcntl(fd, F_SETFL,0));
}
#endif
fcntl(fd, F_SETFL, 0); // set blocked
struct termios options;
tcgetattr(fd, &options);
/* setting the baud rate */
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 15;
tcsetattr(fd, TCSANOW, &options);
if(0 == isatty(fd))
{
printf("input is not a terminal device\n");
//return;
}
int numBytes = write(fd, "Hello, I'm waiting for input..\r\n", 33);
if (numBytes < 0) {
printf("\nFailed to send from COM1!\n");
}
//wait input
printf("wait 5s \n");
(void) rtems_task_wake_after( 5 * rtems_clock_get_ticks_per_second() );
numBytes = read(fd, buffer, 20);
printf("read bytes %d\n", numBytes);
strerror(errno);
if (numBytes < 0) {
printf("\nFailed to read from COM1!\n");
}
else if(numBytes == 0)
{
printf("read error return 0\n");
}
else
{
//buffer[numBytes] = 0; // terminate
printf("rev: %s\n", buffer);
}
close(fd);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20190322/0e71efdb/attachment.html>
More information about the users
mailing list