while(1)
{
// read the data from serial port
bytes_read = read(handle, &by, 1);
if (bytes_read > 0)
{
// echo the sent data back to sender
write(handle, &by, 1);
}//if
}//while
Possibly you have unintentionally enabled two conflicting mechanisms!
I have left the following values at their defaults (presumably zero):
tios.c_cc[VPREDELAY] = 1;
tios.c_cc[VPOSTDELAY] = 1;
The delays are measured in system ticks, which is unnecessarily slow, IMO. (On a quick look in the driver code they appear to be supported - probably treating the RTS pin as a generic output - maybe you need to explicitly set the RTS pin as an output).
If you use the CRTSTOGGLE function when the above delays are zero, it enables a hardware function in the UART.
To give some setup and hold time on RTS, I’ve modified camry_serial.h, about line 20, as follows:
#define RTSEN ((1 << 19) | 0xf) /* extends RTS a little either side of TxData */
You also need to configure the RTS pin as having a function associated with the UART:
NAconfigureGPIOpin(5,NA_GPIO_SELECT_MUX_FUNC0,1); // RTS hooked into UART, normally disabled