Which Pins are you using for UART4 rcv and have you set the PIN mux correctly 
for that PIN?

 

From: beagleboard@googlegroups.com [mailto:beagleboard@googlegroups.com] On 
Behalf Of Piyush Raj ae19m009
Sent: Monday, March 01, 2021 6:30 PM
To: BeagleBoard <beagleboard@googlegroups.com>
Subject: [beagleboard] POCKETBEAGLE: UART Help - Garbage data along with 
requisite data

 

I am implementing UART using Pocketbeagle wherein i am trying to send simple 
strings over UART . I have written a code for loopback testing of UART-4 in PB. 
for a logic Low on P2.1  i am sending String "LOW" and "HIGH" for vice versa. 
However i am getting garbage data along with the requisite strings. sometimes 
all the received data is missing or broken. I tried to work at various baud 
rates (600, 9600,115200) but of no help.

Am i doing any basic mistake. need guidance from community. (I worked with AVR 
and Arduino UART in the past and never faced such problem)

 

Further, i also tried to dump the received data in a text file( to rule out 
possibility of terminal baud rate mismatch), but results did not change.

 

My code is below:

 

 

#include<fstream>

#include<iostream>

#include <string.h>

#include <fcntl.h>

#include <termios.h>

#include<unistd.h> //for usleep

#include"GPIO.h"

using namespace exploringBB;

using namespace std;

 

int main()

{

    GPIO  outLogicSupply(60); outLogicSupply.setDirection(OUTPUT);  

    GPIO  inLogicSupply(59); inLogicSupply.setDirection(INPUT);

 

    int file,count;

    char transmit[6];

    char receive[10];

      int bytes_written,read_code;int count1=1;

    //////////////// OPENING UART4 ON POCKETBEAGLE /////////////////////

    printf("UART: Transmission Started.\n");

    if ((file = open("/dev/ttyO4", O_RDWR | O_NOCTTY | O_NDELAY))<0)

    {

      perror("UART: Failed to open the device.\n");

      return -1;

    }

    else

    {

        printf("UART: Opened file successfully\n");

    }

    /////////////////////////////////////////////////////////////////////

 

   ///////////////    SETTING UP UART OPTIONS  ///////////////////////////

  struct termios options;

   tcgetattr(file, &options);

   options.c_cflag = B9600 | CS8 | CREAD | CLOCAL;

   options.c_iflag = IGNPAR | ICRNL;

   tcflush(file, TCIFLUSH);

   fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);  // make reads non-blocking

   tcsetattr(file, TCSANOW, &options);

  

   cout << "The value of the input is: "<< inLogicSupply.getValue() << endl;

 

 

   while(1)

    {

      

        if(inLogicSupply.getValue()==1)

       

        {

        strcpy(transmit,"HIGH\n");    

         outLogicSupply.setValue(HIGH);

            

        }

        else

        

        {

        strcpy(transmit,"LOW\n");

         outLogicSupply.setValue(LOW);

        }

        

        bytes_written = write(file, &transmit,6);

        sleep(1);

        read_code= read(file,receive,10);

        if(bytes_written>0  && read_code>0  ) 

        {

        receiveFile<<count1<<"sec - "<<receive;

        cout<<count1<<"sec - "<<receive;

       

        }

        count1++;

        sleep(0.01);

      }

  

  ///////////////////////////////////////////////////////////////

     receiveFile.close();

   close(file);

  

   return 0;

}

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com 
<mailto:beagleboard+unsubscr...@googlegroups.com> .
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/99530b73-a474-410b-8583-4d0327d32d35n%40googlegroups.com
 
<https://groups.google.com/d/msgid/beagleboard/99530b73-a474-410b-8583-4d0327d32d35n%40googlegroups.com?utm_medium=email&utm_source=footer>
 .

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/000201d70f2a%24edd15100%24c973f300%24%40comcast.net.

Reply via email to