RTS Toggle does not work on ME9210

Hi

What i’m doing wrong here, RTS does not toggle between high and low for sending. I will appreciated any help !!

This is my code.

printf("Starting port %s

", COM0);

handle = open(COM0, O_RDWR | O_NONBLOCK,0);
if (handle <= 0)
{
  printf("Failed to open %s

", COM0);
return;
}

if (tcgetattr(handle, &tios) < 0)
{
  printf("tcgetattr failed

");
close(handle);
return;
}

tios.c_cflag = CREAD | CS8 | CRTSTOGGLE;
tios.c_iflag = 0;
tios.c_cc[VPREDELAY] = 1;
tios.c_cc[VPOSTDELAY] = 1;
tios.c_oflag = 0;
tios.c_xflag = 0;
tios.c_lflag = 0;

cfsetospeed(&tios, serl_baudrate);

if (tcsetattr(handle, TCSANOW, &tios) < 0)
{
   printf("tcsetattr failed

");
close(handle);
return;
}

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

This has been working OK for me for a long time.

Thanks Steve

It is working .
I added next lines :

NAconfigureGPIOpin(5,NA_GPIO_FUNC0_STATE,0);
NAInvertGPIOpin(5, TRUE);