1

I am attempting to activate a serial port on the Beaglebone black and have connected the TX to the RX. I wrote a test program. In it, I setup my serial port to 1152000 baud and no parity according to help I found at how to open, read, and write from serial port in C. Below is my main function:

int main(void)
{
    char *portname = "/dev/ttyO4";

    int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
    if (fd < 0)
    {
        printf ("error %d opening %s: %s", errno, portname, strerror (errno));
        return 0;
    }

    set_interface_attribs (fd, BAUD_RATE, 0);
    set_blocking (fd, 0);

    while (true)
    {
        write (fd, "Hello!\n", 7);
        char buf [100];
        int n = read (fd, buf, sizeof buf);
        std::cout << buf;
        std::cout.flush();
        sleep(1);
    }

    return 0;
}

When I run it, I read something on the serial port RX, but it isn't hello, it is "ù¶" instead. Can someone tell me why this is happening??

Kind regards

Cornel

Community
  • 1
  • 1
Cornel Verster
  • 1,664
  • 3
  • 27
  • 55
  • How is BAUDRATEBAUD_RATE defined? To clarify, (I believe) it can't just be any number - it has to be a baud rate constant, like `B115200`. – Drew McGowen Aug 07 '13 at 13:36
  • 1
    Why do you write tag [c] but source is C++? – Eddy_Em Aug 07 '13 at 13:38
  • BAUD_RATE is defined #define BAUD_RATE B1152000 – Cornel Verster Aug 07 '13 at 13:41
  • Is the receiving end also setup with the same line parameters? Also, does the board/serial line/receiver support 1152K baud? – Drew McGowen Aug 07 '13 at 13:43
  • you have serial connection established. can you try sending litterals or just integers and see how the device is reading them . it can be an encoding problem .i.e you need to send the string in it is HEX equivalent. – Nadim Farhat Aug 07 '13 at 13:48
  • Getting short strings with lots of bits turned on is a strong selector for setting the baudrate too high. Pretty important too that your program can detect these kind of mishaps, you'll get a framing error from the serial port. – Hans Passant Aug 07 '13 at 13:58
  • Changing the Baud rate to something lower and increasing the size of the string still gives nonsensical readings. It must have something to do with the port, because regardless of the string I send, I still get pretty much the same reading with a bit of variation? – Cornel Verster Aug 07 '13 at 14:05
  • Is your constant really B1152000? RS232 only supports a baud rate of 115200 not 1152000. – chrmue Aug 07 '13 at 14:07
  • right now it is B9600, and same results – Cornel Verster Aug 07 '13 at 14:07
  • @DrewMcGowen: yes, I am using a single serial port for sending and receiving, so it is setup the same. – Cornel Verster Aug 07 '13 at 14:09

0 Answers0