I'm working on a Raspberry Pi Zero W V1, I read the UART is the same for all models except RPi4.
I read there are 2 UART ports and only one of them is a true UART, which is ttyAMA0, aka PL011.
I already disabled BT and I got the port to work. I have a small program that reads the data, I'm only doing RX.
I'm currently reading data at 1,500,000 baud. The problem is that every now and then a byte gets screwed up or missed and it seems like the next byte is 0x00. I'm using very short wires and I'm checking with an oscilloscope to verify the data is being sent correctly, which it is.
I can't figure out why I'm getting these occasional byte errors.
What is the fasted baudrate I'm supposed to be able to use? I read somewhere 4,000,000 baud, is that true? I haven't gone beyond 1,500,000 because it's not correctly working yet.
Maybe I have a problem with my code.
This is the port setup:And this is how I'm reading the data:
I read there are 2 UART ports and only one of them is a true UART, which is ttyAMA0, aka PL011.
I already disabled BT and I got the port to work. I have a small program that reads the data, I'm only doing RX.
I'm currently reading data at 1,500,000 baud. The problem is that every now and then a byte gets screwed up or missed and it seems like the next byte is 0x00. I'm using very short wires and I'm checking with an oscilloscope to verify the data is being sent correctly, which it is.
I can't figure out why I'm getting these occasional byte errors.
What is the fasted baudrate I'm supposed to be able to use? I read somewhere 4,000,000 baud, is that true? I haven't gone beyond 1,500,000 because it's not correctly working yet.
Maybe I have a problem with my code.
This is the port setup:
Code:
int init_uart(void) {int fd_temp; struct termios options; char startup_string[] = "[START]\r\n"; fd_temp = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd_temp == -1) { perror("Failed to open serial port"); return -1; }tcgetattr(fd_temp, &options);cfsetispeed(&options, B1500000);cfsetospeed(&options, B1500000);options.c_cflag &= ~PARENB;options.c_cflag &= ~CSTOPB;options.c_cflag &= ~CSIZE;options.c_cflag |= CS8;options.c_lflag = 0;options.c_oflag = 0;//options.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrloptions.c_iflag &= ~(ICRNL | IXON | IXOFF | IXANY); // Disable CR->NL translation and software flow controloptions.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,// enable readingoptions.c_cflag &= ~(PARENB | PARODD); // shut off parityoptions.c_cflag &= ~CSTOPB;options.c_cflag &= ~CRTSCTS;options.c_cc[VMIN] = 0; // read doesn't block//options.c_cc[VTIME] = 5; // 0.5 seconds read timeoutoptions.c_cc[VTIME] = 50;tcsetattr(fd_temp, TCSANOW, &options); write(fd_temp, startup_string, sizeof(startup_string));return fd_temp;}
Code:
bytes_read = read(fd, buffer, 200);if (bytes_read > 0) {...
Statistics: Posted by KingJoffrey — Thu Apr 11, 2024 7:44 pm — Replies 3 — Views 39