Setting Up Serial in GCC

15 views
Skip to first unread message

woody stanford

unread,
Jan 28, 2017, 6:56:18 PM1/28/17
to BeagleBoard
Love Python, however I am a dyed-in-the-wool GCC C/C++ programmer for decades.My question has to do with GCC.

OK, I realized that I needed to configure the BBB R3 so that its P8 and P9 pins were set for UART (got that far myself). I kind of took an overkill approach.

What I did was I copied uEnv.txt from /boot to /boot/uboot (tell me if I did this right...does the supplied OS read uEnv.txt from there...everytime I tried modifying the original /boot/uEnv.txt it told me it was a read-only filesystem) ? Then in /boot/uboot/uEnv.txt I put the line in:

cape_enable=bone_capemgr.enable_partno=BB-UART1,BB-UART2,BB-UART3,BB-UART4,BB-UART5

(I just thought I'd turn them all on...I have a big project I'm working on)

I was thinking that these would map over to ttyO1 thru ttyO5. Correct? Tell me if this doesn't do this as my program isn't working.

Then I came out with a shell script (that I call uart.sh) that has this in it:

config-pin overlay cape-universal
config-pin P9.21 uart
config-pin P9.22 uart
config-pin P9.24 uart
config-pin P9.26 uart

....made it executable and ran that. So I'm thinking my board is really UART-ized.

Now here's the question. I have a C program that transmits over ttyO1 and receives on ttyO2, and I put a physical jumper between p9.22 (UART2 RX) and p9.24 (UART1 TX). However I can't get it to work.

Here is some code snippets from the C source code.

I open the ports using code like this:

int fd1, fd2;

open_ports()
{
fd1 = open("/dev/ttyO1", O_RDWR | O_NOCTTY | O_NDELAY);
fd1 = open("/dev/ttyO2", O_RDWR | O_NOCTTY | O_NDELAY);

etc. etc.

and here is my main code:

main()
{
        int n;
        char buf[255];
        int res=0;

        open_ports();
        printf("Ports /dev/ttyO1 and /dev/ttyO2 opened\n\n");

        fcntl(fd2, F_SETFL, 0); //set up receive for BLOCKING

        n = write(fd1, "COMMAND STRING\n", 4);
        if (n < 0)
        fputs("write() of 4 bytes failed!\n", stderr);
//      fflush(NULL);

        printf("Receiving command...\n");
        res=read(fd2,buf,255);
        printf("Received Command: %s\n",buf);

}

DOESN'T WORK. Ouchies. Any ideas...I'm all ears. Thanks in advance.




Reply all
Reply to author
Forward
0 new messages