Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
12
Return to list New
Author: bigmac

Multiple UART

[Copy link]

10

Threads

220

Posts

2000

Credits

Gold member

Rank: 6Rank: 6

Credits
2000
Post time 2016-7-6 06:58:46 | Show all posts
I confirmed that it can be received in 2 of UART at the same time using in separate process.
2 of uart may not be able to use it in single process at the same time.

The OS I use is below.
Armbian_5.13_Orangepione_Debian_jessie_3.4.112

7

Threads

19

Posts

209

Credits

Intermediate member

Rank: 3Rank: 3

Credits
209
Post time 2016-7-6 11:48:49 | Show all posts
Thanks for your help nopnop2002, but the story isn't over yet, I'm afraid.
I typed what you said, except I used "cd wiringOP" instead of "cd wiringOP/".
When I try to compile my program Hub.c and link to your library, it can't find the object files. Please see attachment picture.
Is there a further step that I should do?
Thanks again for your patience.

This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x

10

Threads

220

Posts

2000

Credits

Gold member

Rank: 6Rank: 6

Credits
2000
Post time 2016-7-6 22:18:55 | Show all posts
Ashtonites replied at 2016-7-6 11:48
Thanks for your help nopnop2002, but the story isn't over yet, I'm afraid.
I typed what you said, ex ...

Link is same as RPI.
cc -o hoge hoge.c -lwiringPi

7

Threads

19

Posts

209

Credits

Intermediate member

Rank: 3Rank: 3

Credits
209
Post time 2016-7-6 23:51:20 | Show all posts
It compiles !!!! Thank you so much for your patience with a novice. I've never worked on an OPi or RPi before so it's all new to me.

7

Threads

19

Posts

209

Credits

Intermediate member

Rank: 3Rank: 3

Credits
209
Post time 2016-7-7 02:17:11 | Show all posts
I have a related question, so I'm not opening a new thread:
The hardware to which my OPi UART is connected operates at a non-standard baud rate because of clock issues on it. Rather than change a lot of software on it, I would like to run the OPi UART at 250000 baud. serialOpen on the OPi allows only standard baud rates. I think that there are two possibilities:
1. using Google, some people on the RPi have changed the init_uart_clock value... (see https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=73673). Possibly serialOpen assumes whatever value is set in /etc/config.txt or boot/config.txt, so by changing init_uart_clock you trick serialOpen so that, for instance, 115,200 baud can become 250000 baud by increasing the current init_uart_clock by the right factor. I don't know if init_uart_clock exists on the OPi... maybe there is a setting in the FEX.
2. modify serialOpen to allow a baudrate of 250000 value (I think serialOpen just uses termios so this method may not work).
Has anybody tried this. or can recommend a technique?

3

Threads

10

Posts

111

Credits

Registered member

Rank: 2

Credits
111
 Author| Post time 2016-7-7 02:31:12 | Show all posts
Wow I've not seen that baudrate before!
First check your fex in order to set the needed uart(s) and kind of (2,4 or 8) then try setting the speed by stty -F /dev/ttyS1 (or 2 or 3) space baudrate i.e 9600 (or the needed baudrate allowed by the board (i've tried up to 115200, not sure about the one you specify)

stty -F /dev/ttyS1 96000 to get 9600 bauds 1n8 on uart 1 (ttyS1)

Hope it works for you

10

Threads

220

Posts

2000

Credits

Gold member

Rank: 6Rank: 6

Credits
2000
Post time 2016-7-13 06:03:19 | Show all posts

cfsetispeed() sets the input baud rate stored in the termios structure to spe...

Edited by nopnop2002 at 2016-7-13 06:15
Ashtonites replied at 2016-7-7 02:17
I have a related question, so I'm not opening a new thread:
The hardware to which my OPi UART is con ...

Here is Man Page of cfsetospeed function.
http://linux.die.net/man/3/cfsetispeed

cfsetospeed() sets the output baud rate stored in the termios structure pointed to by termios_p to speed, which must be one of these constants:

B0
B50
B75
B110
B134
B150
B200
B300
B600
B1200
B1800
B2400
B4800
B9600
B19200
B38400
B57600
B115200
B230400

The zero baud rate, B0, is used to terminate the connection. If B0 is specified, the modem control lines shall no longer be asserted. Normally, this will disconnect the line. CBAUDEX is a mask for the speeds beyond those defined in POSIX.1 (57600 and above). Thus, B57600 & CBAUDEX is nonzero.
cfgetispeed() returns the input baud rate stored in the termios structure.

cfsetispeed() sets the input baud rate stored in the termios structure to speed, which must be specified as one of the Bnnn constants listed above for cfsetospeed(). If the input baud rate is set to zero, the input baud rate will be equal to the output baud rate.

cfsetspeed() is a 4.4BSD extension. It takes the same arguments as cfsetispeed(), and sets both input and output speed.


I think I can't set it as 250000 baud rate.

3

Threads

10

Posts

111

Credits

Registered member

Rank: 2

Credits
111
 Author| Post time 2016-7-13 20:53:55 | Show all posts
By the way you need to ask your hardware the supported baudrate in order to see if above can be set. ( normally 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200)

some USB 2 RS232 may do the trick
http://www.prolific.com.tw/US/ShowProduct.aspx?pcid=41

10

Threads

220

Posts

2000

Credits

Gold member

Rank: 6Rank: 6

Credits
2000
Post time 2016-7-31 12:30:54 | Show all posts
I tried two serial communication at the same time.
It's work fine.

  1. //
  2. // Serial Receive Program
  3. //
  4. // cc -o serialR serialR.c -lwiringPi
  5. //
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <errno.h>
  9. #include <wiringPi.h>
  10. #include <wiringSerial.h>

  11. #define    DEBUG    0

  12. int readSerial(int fd, char * buff, int blen, int timeout) {
  13.   unsigned long endTime;
  14.   int ch;
  15.   int pos = 0;

  16. if(DEBUG)printf("millis=%d\n",millis());
  17.   endTime = millis () + timeout;
  18. if(DEBUG)printf("endTime=%d\n",endTime);
  19.   buff[pos] = 0;

  20.   while (1) {
  21.     if (millis () > endTime) return -1;
  22.     if (serialDataAvail (fd)) {
  23.       ch = serialGetchar (fd);
  24. if(DEBUG)printf (" -> %02x\n", ch);
  25.       if (ch == 0x0d) {

  26.       } else if (ch == 0x0a) {
  27.         return pos;
  28.       } else {
  29.         if (pos < blen) buff[pos++] = ch;
  30.         if (pos < blen) buff[pos] = 0;
  31.       }
  32.     } // end if
  33.   } // end while
  34. }


  35. int main (int argc, char **argv) {
  36.   int fd1;
  37.   int fd2;
  38.   int len;
  39.   char buff[64];
  40.   char device1[32];
  41.   char device2[32];

  42.   memset(device1,0,sizeof(device1));
  43.   memset(device2,0,sizeof(device2));

  44.   strcpy(device1,"/dev/ttyAMA0");
  45.   if (argc >= 2) strcpy(device1,argv[1]);
  46.   if (argc >= 3) strcpy(device2,argv[2]);
  47.   printf("device1=[%s] device2=[%s]\n",device1,device2);

  48.   if ((fd1 = serialOpen (device1, 115200)) < 0) {
  49.     printf ("Unable to open serial device1: %s\n", strerror (errno)) ;
  50.     return 1 ;
  51.   }

  52.   if (strlen(device2) > 0) {
  53.     if ((fd2 = serialOpen (device2, 115200)) < 0) {
  54.       printf ("Unable to open serial device2: %s\n", strerror (errno)) ;
  55.       return 1 ;
  56.     }

  57.   }

  58.   if (wiringPiSetup () == -1) {
  59.     printf ("Unable to start wiringPi: %s\n", strerror (errno)) ;
  60.     return 1 ;
  61.   }
  62.   printf("wiringPiSetup\n");

  63.   while(1) {
  64. //  Receive data
  65.     len=readSerial(fd1, buff, sizeof(buff),100);
  66.     if (len != -1) {
  67.       printf("readSerial(device1) data=[%s]\n",buff);
  68. //    Send data
  69.       serialPrintf (fd1,"You are Welcome!! This is %s\n",device1);
  70.     }

  71.     len=readSerial(fd2, buff, sizeof(buff),100);
  72.     if (len != -1) {
  73.       printf("readSerial(device2) data=[%s]\n",buff);
  74. //    Send data
  75.       serialPrintf (fd2,"You are Welcome!! This is %s\n",device2);
  76.     }
  77.   }
  78. }
Copy the Code


This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x
12
Return to list New
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-11-15 21:06 GMT+8 , Processed in 0.033097 second(s), 20 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list