Hello i have make one serial port read data below code and i am transmit data fron pc. so i am not able to read data on mini2440 board. I am tired to solving this issue...please help me...if you have solution... Below is my read data code at mini2440 side: #include <stdio.h> #include <termios.h> //header contains the definitions used by the terminal I/O interfaces #include <unistd.h> //read() write() close() #include <fcntl.h> #include <string.h> //Serial port defines and variables: #define BAUDRATE B9600 #define SERIAL_PATH "/dev/ttyS0" int serial_fd; int serial_read_ret, serial_write_ret; struct termios serial_settings; char serial_buffer_send[1024] = "Test"; char serial_buffer_recv[1024] = {0}; int main() { printf("Program to write a string to the serial port and read a string from it.\n"); printf("Make sure to run this program with elevated privileges.\n\n"); printf("Opening %s in Read/Write mode at 8-N-1...",SERIAL_PATH); fflush(stdout); //Try opening serial port serial_fd = open(SERIAL_PATH,O_RDWR | O_NOCTTY | O_NONBLOCK); // serial_fd = open(SERIAL_PATH,O_RDWR|O_NOCTTY ); if(serial_fd == -1) { //Checks the availability of the Serial Port printf("Failed.\n"); fflush(stdout); return 0; } else { printf("Success.\n"); fflush(stdout); //Get serial port settings tcgetattr(serial_fd, &serial_settings); //Get Current Settings of the Port cfsetispeed(&serial_settings,BAUDRATE); //Set Input Baudrate cfsetospeed(&serial_settings,BAUDRATE); //Set Output Baudrate serial_settings.c_cflag &= ~PARENB; //Mask Parity Bit as No Parity serial_settings.c_cflag &= ~CSTOPB; //Set Stop Bits as 1 or else it will be 2 serial_settings.c_cflag &= ~CSIZE; //Clear the current no. of data bit setting serial_settings.c_cflag |= CS8; //Set no. of data bits as 8 Bits } // serial_write_ret = write(serial_fd,serial_buffer_send,strlen(serial_buffer_send)); //printf("Sent to serial port: %s\n",serial_buffer_send); while(1) { serial_read_ret = read(serial_fd,serial_buffer_recv,sizeof(serial_buffer_recv)); printf("Read from serial port: %s\n",serial_buffer_recv); sleep(1); } serial_read_ret = close(serial_fd); //Close the serial port printf("Serial port closed.\n\n"); return 0; } root@dipen:~/Desktop/serial_test# vi test_read.c root@dipen:~/Desktop/serial_test# vi test_read.c root@dipen:~/Desktop/serial_test# cat test_read.c #include <stdio.h> #include <termios.h> //header contains the definitions used by the terminal I/O interfaces #include <unistd.h> //read() write() close() #include <fcntl.h> #include <string.h> //Serial port defines and variables: #define BAUDRATE B9600 #define SERIAL_PATH "/dev/ttySAC0" int serial_fd; int serial_read_ret, serial_write_ret; struct termios serial_settings; char serial_buffer_send[1024] = "Test"; char serial_buffer_recv[1024] = {0}; int main() { printf("Program to write a string to the serial port and read a string from it.\n"); printf("Make sure to run this program with elevated privileges.\n\n"); printf("Opening %s in Read/Write mode at 8-N-1...",SERIAL_PATH); fflush(stdout); //Try opening serial port serial_fd = open(SERIAL_PATH,O_RDWR | O_NOCTTY | O_NONBLOCK); // serial_fd = open(SERIAL_PATH,O_RDWR|O_NOCTTY ); if(serial_fd == -1) { //Checks the availability of the Serial Port printf("Failed.\n"); fflush(stdout); return 0; } else { printf("Success.\n"); fflush(stdout); //Get serial port settings tcgetattr(serial_fd, &serial_settings); //Get Current Settings of the Port cfsetispeed(&serial_settings,BAUDRATE); //Set Input Baudrate cfsetospeed(&serial_settings,BAUDRATE); //Set Output Baudrate serial_settings.c_cflag &= ~PARENB; //Mask Parity Bit as No Parity serial_settings.c_cflag &= ~CSTOPB; //Set Stop Bits as 1 or else it will be 2 serial_settings.c_cflag &= ~CSIZE; //Clear the current no. of data bit setting serial_settings.c_cflag |= CS8; //Set no. of data bits as 8 Bits } // serial_write_ret = write(serial_fd,serial_buffer_send,strlen(serial_buffer_send)); //printf("Sent to serial port: %s\n",serial_buffer_send); while(1) { serial_read_ret = read(serial_fd,serial_buffer_recv,sizeof(serial_buffer_recv)); printf("Read from serial port: %s\n",serial_buffer_recv); sleep(1); } serial_read_ret = close(serial_fd); //Close the serial port printf("Serial port closed.\n\n"); return 0; } ///Below is my Write Data COde at PC side #include <stdio.h> #include <termios.h> //header contains the definitions used by the terminal I/O interfaces #include <unistd.h> //read() write() close() #include <fcntl.h> #include <string.h> //Serial port defines and variables: #define BAUDRATE B9600 #define SERIAL_PATH "/dev/ttyS0" int serial_fd; int serial_read_ret, serial_write_ret; struct termios serial_settings; char serial_buffer_send[1024] = "Test"; char serial_buffer_recv[1024] = {0}; int main() { printf("Program to write a string to the serial port and read a string from it.\n"); printf("Make sure to run this program with elevated privileges.\n\n"); printf("Opening %s in Read/Write mode at 8-N-1...",SERIAL_PATH); fflush(stdout); //Try opening serial port serial_fd = open(SERIAL_PATH,O_RDWR|O_NOCTTY); if(serial_fd == -1) { //Checks the availability of the Serial Port printf("Failed.\n"); fflush(stdout); return 0; } else { printf("Success.\n"); fflush(stdout); //Get serial port settings tcgetattr(serial_fd, &serial_settings); //Get Current Settings of the Port cfsetispeed(&serial_settings,BAUDRATE); //Set Input Baudrate cfsetospeed(&serial_settings,BAUDRATE); //Set Output Baudrate serial_settings.c_cflag &= ~PARENB; //Mask Parity Bit as No Parity serial_settings.c_cflag &= ~CSTOPB; //Set Stop Bits as 1 or else it will be 2 serial_settings.c_cflag &= ~CSIZE; //Clear the current no. of data bit setting serial_settings.c_cflag |= CS8; //Set no. of data bits as 8 Bits } while(1) { serial_write_ret = write(serial_fd,serial_buffer_send,strlen(serial_buffer_send)); printf("serial write lenth %d\n",serial_write_ret); printf("Sent to serial port: %s\n",serial_buffer_send); sleep(1); } serial_read_ret = close(serial_fd); //Close the serial port printf("Serial port closed.\n\n"); return 0; }
mini2440 serial port data not received
Under the mini2440 section: #define SERIAL_PATH "/dev/ttyS0" Is there really a ttys0 in your /dev? I think you will only find that on your PC host. There was a thread similar to this recently. Think you will find ttySAC0 or ttySAC1 is what you need on the mini2440?
Mini2440 side read serial port code.... #include <stdio.h> #include <termios.h> //header contains the definitions used by the terminal I/O interfaces #include <unistd.h> //read() write() close() #include <fcntl.h> #include <string.h> //Serial port defines and variables: #define BAUDRATE B9600 #define SERIAL_PATH "/dev/ttySAC0" int serial_fd; int serial_read_ret, serial_write_ret; struct termios serial_settings; char serial_buffer_send[1024] = "Test"; char serial_buffer_recv[1024] = {0}; int main() { printf("Program to write a string to the serial port and read a string from it.\n"); printf("Make sure to run this program with elevated privileges.\n\n"); printf("Opening %s in Read/Write mode at 8-N-1...",SERIAL_PATH); fflush(stdout); //Try opening serial port serial_fd = open(SERIAL_PATH,O_RDWR | O_NOCTTY | O_NONBLOCK); // serial_fd = open(SERIAL_PATH,O_RDWR|O_NOCTTY ); if(serial_fd == -1) { //Checks the availability of the Serial Port printf("Failed.\n"); fflush(stdout); return 0; } else { printf("Success.\n"); fflush(stdout); //Get serial port settings tcgetattr(serial_fd, &serial_settings); //Get Current Settings of the Port cfsetispeed(&serial_settings,BAUDRATE); //Set Input Baudrate cfsetospeed(&serial_settings,BAUDRATE); //Set Output Baudrate serial_settings.c_cflag &= ~PARENB; //Mask Parity Bit as No Parity serial_settings.c_cflag &= ~CSTOPB; //Set Stop Bits as 1 or else it will be 2 serial_settings.c_cflag &= ~CSIZE; //Clear the current no. of data bit setting serial_settings.c_cflag |= CS8; //Set no. of data bits as 8 Bits } // serial_write_ret = write(serial_fd,serial_buffer_send,strlen(serial_buffer_send)); //printf("Sent to serial port: %s\n",serial_buffer_send); while(1) { serial_read_ret = read(serial_fd,serial_buffer_recv,sizeof(serial_buffer_recv)); printf("Read from serial port: %s\n",serial_buffer_recv); sleep(1); } serial_read_ret = close(serial_fd); //Close the serial port printf("Serial port closed.\n\n"); return 0; }
Not much point in double-posting. Have you confirmed that you can communicate with the mini2440 using minicom on your host?
yes..problblem is i am not able to receive data on serial port.but i can transmit it. Below is N-8-1 serial_settings.c_cflag &= ~PARENB; //Mask Parity Bit as No Parity serial_settings.c_cflag &= ~CSTOPB; //Set Stop Bits as 1 or else it will be 2 serial_settings.c_cflag &= ~CSIZE; //Clear the current no. of data bit setting serial_settings.c_cflag |= CS8; //Set no. of data bits as 8 Bits
Are you connecting your external serial device to the DB9 connector or to one of the TTL level white connectors?
yes using minicom work perfectly.... but i am used rs232(ttySAC0) port and ttl(ttySAC1) port. ////////////////////////////////////////////////// Condition:1 (mini2440 <---> external device) Not Receive Data When i am sending hex data to external device so exrenal device not give me return back data. so i am not able to receive data from my mini2440 to external device through serial port. ///////////////////////////////////////////////////// Condition:2 (PC <---> external device) Successful receive data but same code i used in pc so external device give me retuen data. So i think is there any problem related to due to cross compilation in hex data structure?
So i think is there any problem related to due to cross compilation in hex data structure? Have you check that the resulting cross-compiled file is for the armv4t architecture? On the command line on your host type: readelf -a <filename> or readeld -A <filename> The last few lines are what you are looking for. You should see something about armv4t
You should handle ICANON in your little program ("man tcgetattr" -> section "Canonical and noncanonical mode"). Take a look into the "microcom" sources how to setup a serial line for your purpose. To check the connection I would also recommend to test it with "microcom" or similar terminal programs on your Mini2440 first and *then* switch to your own program.
Thanks For All Help... My Problem Is Resolve . So is there not problem in coding side. Read Below Reason: My external serial port hardware work on 15v and mini2440 serial port work on 5V So due to this reason data is not send and receive. so between this two i put two max232 IC that convert 15 to 5 and vice versa. so my problem resolve. Thanks...
Huh? > Are you connecting your external serial device to the DB9 connector > or to one of the TTL level white connectors? So, the answer should have been "I am not using the DB9 connector"
hello davef, i have mini6410 and i want transmitt and receive the data from serial but the rs232 port is not access it is on ttySAC0.... what is the problm i can't understand... can you help me please.
First, have you got minicom or some terminal program set to ttySAC0? Have you got the correct RS232 cable, ie the one that came with the mini6410? Try swapping end for end, it was a fix for some people. What distribution are you running? Have you changed any of the tty? Do you see /dev/ttySAC0 ?