Hi all, I m using AT91SAM9260 evaluation kit board,
I m trying to get reading and writing on AT91SAM9260 via com I/O. I connecte the board with PC, I write from the board to the PC, and it runs. but when I try the same thing but from PC to the board, it does nt work heir is the code that I use.
[b][color=#000000]the code for writing[/color][/b] [code]#include <stdio.h> #include <string.h>
#include <unistd.h> #include <fcntl.h> #include <errno.h> #include <termios.h>
int initport(int portCom) { struct termios options; // Get the current options for the port... tcgetattr(portCom, &options); // Set the baud rates to 9600.. cfsetispeed(&options, B115200); cfsetospeed(&options, B115200); // Enable the receiver and set local mode... options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8;
// Set the new options for the port... tcsetattr(portCom, TCSANOW, &options); return 1; } int portCom; int main(){
portCom = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); if (portCom == -1) { printf("port enable to open"); perror("open_port: Unable to open /dev/ttyS0 - "); return 1; }else{ printf("ofor wriiiting\n"); } initport(portCom); while(1==1){ usleep(10000); if(write(portCom,"coming",6)){ printf("writen\n"); } } close(portCom); }[/code]
[b][color=#000000]the code for reading:[/color][/b] [code]#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <termios.h>
options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; // Set the new options for the port... tcsetattr(portCom, TCSANOW, &options); return 1; } int portCom; char word[254]; int main(){ portCom = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NDELAY); if (portCom == -1) { printf("port enable to open"); perror("open_port: Unable to open /dev/ttyS0 - "); return 1; }else{ fcntl(portCom, F_SETFL, 0); //fcntl(portCom, F_SETFL, FNDELAY); printf("for reading\n"); } initport(portCom); //while(1==1){ usleep(100000); int iIn = read(portCom, word, 254); word[iIn-1] = 0x00; if (iIn < 0) { if (errno == EAGAIN) { printf("SERIAL EAGAIN ERROR\n"); return 0; } else { printf("SERIAL read error %d %s\n", errno, strerror(errno)); return 0; } } printf("\n%s",word); //} close(portCom); }[/code]
Cheers