RS485 with UART from LS1021a

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RS485 with UART from LS1021a

Jump to solution
1,838 Views
janbrand
Contributor II

Hello!

I want to use RS485 through the UART1 from a costum Board. UART1_SIN, UART1_SOUT and UART1_RTS are connected to the RS485 Transceiver. I'm using the QorIQ 1.8 SDK. Receiving data from a PC through RS485 is possible with cat /dev/ttyS0.

For Sending data from my board there has to be a driver to set the RTS-Signal, because Linux thinks ttyS0 is a normal RS232 (correct me if I'm wrong). So I first modified my device tree for the board:

&duart0 {

  linux,rs485-enabled-at-boot-time;

  rs485-rts-delay = <0 200>;

  uart-has-rs485-half-duplex;

  rs485-mode = <1>;

  status = "okay";

};

then i searched different communities and copied/wrote a little application trying to send data through RS485:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <asm-generic/ioctl.h>

#include <asm-generic/fcntl.h>

#include <errno.h>

#include <termios.h>

#include <linux/serial.h>

#include <asm-generic/ioctls.h>

//Control struct for setting the port in 485 mode

int main(void){

  struct serial_rs485 rs485conf;

  int rv, i;

  char buffer[20];

  

  int fd = open ("/dev/ttyS0", O_RDWR);

  if (fd < 0) {

         /* Error handling. See errno. */

       printf("Error!\n");

  return 0;

  }

 

  rs485conf.flags |= SER_RS485_ENABLED;

  rs485conf.flags |= SER_RS485_RTS_ON_SEND;

  rs485conf.delay_rts_before_send = 0;

  

  rv = ioctl(fd,TIOCSRS485, &rs485conf);

  if(rv){

      printf("rv = %d\n", rv);

       perror("unable to set IOCTL:");

  }

   for (i=0; i<20; i++){

       buffer[i] = 'A' + i;

  }

 

  for (i=0; i<30;i++){

       printf("Writing [%d]\n", i);

       write(fd, buffer, 20);

       sleep(1);

  }

  rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);

  close(fd);

return 0;

}

when i execute this code after compiling and building, there comes the following message:

"unable to set IOCTL:: Inappropriate ioctl for device"

Does that mean, that the ioctl() does not support TIOCSRS485 and so the RS485 structure, yet? In the serial.h the struct serial_rs485 is already implementet. Do i missed something? I'm confused about the depth RS485 is integrated in the kernel...

What can i do, to get RS485 work?

king regards,

Jan

0 Kudos
1 Solution
877 Views
Pavel
NXP Employee
NXP Employee

The LS1021A Linux serial driver is common serial driver. Look at the following pages for manual setting the RTS signal:

http://www.linuxquestions.org/questions/programming-9/manually-controlling-rts-cts-326590/

https://www.kernel.org/doc/Documentation/serial/driver

http://frank.harvard.edu/~coldwell/terminals/


Have a great day,
Pavel Chubakov

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
878 Views
Pavel
NXP Employee
NXP Employee

The LS1021A Linux serial driver is common serial driver. Look at the following pages for manual setting the RTS signal:

http://www.linuxquestions.org/questions/programming-9/manually-controlling-rts-cts-326590/

https://www.kernel.org/doc/Documentation/serial/driver

http://frank.harvard.edu/~coldwell/terminals/


Have a great day,
Pavel Chubakov

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
877 Views
janbrand
Contributor II

Hi Pavel,

thank you for this advice! The first link was helpful. I included the setRTS function before sending a message!

Have a great day,

Jan

0 Kudos