UART communication(Universal Asynchronous Receiver/Transmitter)

The UART communication protocol is composed of three electric wire
Tx == transmission
Rx == Reception
GND == reference 0V
the alimentation of Tx and Rx pins is +or- equal at +12v, -12v.
For using the UART library you must install the librs232 on Angstrom
CMD: opkg install librs232
the serial link allows communication with the dsPIC. for example if
you want to move the robot, the Beagelboard send a tram towards of
dsPIC. see Communication protocol in part "5) Study" for more
information

Description of use to librs232:

initialisation
// declare and initialize the structure at null
struct rs232_port_t *p = NULL;
// initialize the serial link
p = rs232_init();
// choose the port of communication
rs232_set_device(p, "/dev/ttyO2");
// open the serial link
ret = rs232_open(p);

speed
// choose the speed
rs232_set_baud(p, RS232_BAUD_115200);

send
// write the character
ret = rs232_write_timeout(p, data, 1, &bytes, 1000);

receive
// read the character
ret = rs232_read_timeout(p, data, 1, &bytes, 1000);

close
// close the serial link
rs232_end(p);

please look the example of constructor at next address:
https://github.com/ynezz/librs232/blob/master/src/rs232_test.c

or:

#include "stdio.h"
#include "stdlib.h"
#include "termios.h"
#include "fcntl.h"
 
void raw_mode (fd, old_term)
   int fd;
   struct termios *old_term;
{
   struct termios term;
   tcgetattr(fd, &term);
 
   /* Sauve l’ancienne config dans le paramètre */
   tcgetattr(fd, old_term);
   /* mode RAW, pas de mode canonique, pas d’echo */
   term.c_iflag = IGNBRK;
   term.c_lflag = 0;
   term.c_oflag = 0;
   /* Controle de flux hardware RTS/CTS)
    * term.c_cflag |= (CREAD | CRTSCTS);
    * 1 caractère suffit */
   term.c_cc[VMIN] = 1;
   /* Donnée disponible immédiatement */
   term.c_cc[VTIME] = 0;
   /* Inhibe le controle de flux XON/XOFF */
   term.c_iflag &= ~(IXON|IXOFF|IXANY);
   /* 8 bits de données, pas de parité */
   term.c_cflag &= ~(PARENB | CSIZE);
   term.c_cflag |= CS8;
   /* Gestion des signaux modem */
   term.c_cflag &= ~CLOCAL;
   tcsetattr(fd, TCSANOW, &term);
}
 
main (int ac, char **av)
{
   int fd;
   struct termios tty, old;
   /* Ouverture du device */
   if ((fd = open (av[1], O_RDWR)) < 0) {
      perror (av[1]);
      exit (1);
   }
   /* Lecture des paramètres */
   tcgetattr(fd, &tty);
   tcgetattr(fd, &old);
   /* On passe la vitesse à 0 ==> hangup */
   cfsetospeed(&tty, B0);
   cfsetispeed(&tty, B0);
   /* On applique le nouveau paramètrage pendant 1s */
   tcsetattr(fd, TCSANOW, &tty);
   sleep(1);
   write(fd, "Mras2an", sizeof(char) * 15);
   sleep(1);
   /* On revient à l’ancien et on quitte */
   tcsetattr(fd, TCSANOW, &old);
   close (fd);
}  

 

Sujet: UART

Aucun message nʼ a été trouvé.

Nouvel avis