Go Down

Topic: help for serial/usb PC-ARduino (Read 343 times) previous topic - next topic

dadycoke

Hello, could someone tell me why I am obliged to start a terminal emulation program (eg minicom)
  to communicate with my arduino board (using a C program and a serial connection / usb)

Thank you for your help

PaulS

Quote
Hello, could someone tell me why I am obliged to start a terminal emulation program (eg minicom)
  to communicate with my arduino board (using a C program and a serial connection / usb)

Because you are not opening the serial port correctly in your C program. Fix line 28.

dadycoke

Thanks for your response
Quote
Fix line 28.

i'am not understand what you mean.

I open the port in this way
Code: [Select]
uart0_filestream = open("/dev/ttyACM0",O_RDWR | O_NOCTTY);
if (uart0_filestream == -1)
{
//ERROR - CAN'T OPEN SERIAL PORT
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
}
struct termios options;
tcgetattr(uart0_filestream, &options);
cfsetispeed(&options, B9600); //<Set baud rate
cfsetospeed(&options, B9600); //<Set baud rate
options.c_cflag = B9600 | CS8 | CLOCAL | CREAD; //<Set baud rate
options.c_iflag = IGNPAR | ICRNL;
options.c_oflag = 0;
tcflush(uart0_filestream, TCIFLUSH);
tcsetattr(uart0_filestream, TCSANOW, &options);
fcntl(uart0_filestream, F_SETFL, 0);


and i read
Code: [Select]
for ( count=0; count<5;){
rx_length = -1;
char recevchar;
while (rx_length < 1){
errno = 0;
rx_length = read(uart0_filestream,&recevchar,1);
printf("rx_length : %d\n", rx_length);
printf("errno : %d\n", errno);
printf("caractere : %c\n",recevchar);
if (errno == EAGAIN){
//printf("%d\n", errno);
rx_length = -1;
sleep(1);
  }
}
rx_buffer[count] = recevchar;
++count
}

dadycoke

when the emulator is open my program ( C programme) returns the byte read

PaulS

Quote
i'am not understand what you mean.

Sure you did. You posted (some of) your code.

Go Up