11 Replies Latest reply on Dec 5, 2014 8:31 PM by pctj101

    Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)


      I have a serial device (PN532) hooked up to /dev/ttyMFD1 @ 115200 Baud


      Typically if I hook up the same serial device to a PC/Mac/BBB, it waits for data, then replies.  However for the edison, /dev/ttyMFD1 just continues to spew garbage after garbage.


      I've tried to set the GPIO directions/muxes, but it doesn't seem to make a material difference.


      I've tried solutions as follows:

      Serial problem with edison




      They're both roughly the same.  Tristate, export pins, set mux, set direction, set pullups, finish tristate.


      I've also tried setting the port baud rate using:

      stty -F /dev/ttyMFD1 115200

      Then verified  by


      stty -F /dev/ttyMFD1 -a 


      speed 115200 baud;stty: /dev/ttyMFD1

      line = 0;

      intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q;

      stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;

      -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts

      -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8

      opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0

      isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

      Yup looks good @ 115200

      From there whether I use a program (golang) or simply 'cat' the port, I get continual garbage.

      ** interestingly enough, if I unhook RX, the garbage stops.  So it's not completely random.  There must be something else to this mystery.

      Is there anything else you would recommend that I try?


      Thanks a bunch everybody!

        • 1. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

          Hi pctj101


          Are you sure the parameters of the device are the ones that are set:  8 data bits (cs8), no parity (-parenb, -parodd) and 1 stop bit (-cstopb)?

          I found this other thread about the same device, but in this case is using the IDE.

          Also, Could you attach a picture of what are you receiving?




          • 2. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)



            What I expect is something like 00FF00........ (Where that 00FF00 is the preamble marking start of an incoming packet)


            But... even without requesting any data I get the folowing:


            From Run #1 (In hex) is:



            On a second run I get:



            It looks like there is some kind of random pattern here, but I don't really see it... not enough to figure out the problem.

            I'm pretty sure the baud rate/parity/stop bits are right, but I can confirm in a few hours when I have more time.

            • 3. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

              I am not sure how much this will help, but...


              I know when I started playing around with using an XBee connected to an XBee shield using this IO port, that I had to play around with the code for awhile to get it to work right for me.   The first set of code I got working is my Robot (Arm or Hex or) controlled by Edison talking to Arbotix Commander Remote control.


              Note: My c/c++ code creates a thread to actually process the IO.  I also open it as device /dev/ttyXBEE where I create an alias to this port.  I am also using the port at the speed 38400...  This code earlier worked on BBBk, ODroid U2/U3, RPI...  But I modified it to be closer to the init code that the Arduino IDE does for the Serial1 object.


              The initial Init code looks like:

              bool Commander::begin(char *pszDevice,  speed_t baud)
                  int err;
                  // Create our lock to make sure we can do stuff safely
                  if (pthread_mutex_init(&lock, NULL) != 0)
                      return false;
                  _fCancel = false;    // Flag to let our thread(s) know to abort.
              #ifdef CMDR_USE_XBEE
                  _pszDevice = pszDevice;
                  _baud = baud;
                  // Lets do our init of the xbee here.
                  // We will do all of the stuff to intialize the serial port plus we will spawn off our thread.
                  struct termios tc, tcNew;
                  if ((fdXBee = open(_pszDevice, O_RDWR | O_NONBLOCK)) == -1) 
                      printf("Open Failed\n");
                      return 0;
                  if (tcgetattr(fdXBee, &tc))
                      return 0;
                  // build new version
                     bzero(&tcNew, sizeof(tcNew));
                  //newtios.c_cflag |= _dwBaudRate | CRTSCTS | CS8 | CLOCAL | CREAD;
                  tcNew.c_cflag = tc.c_cflag;
                  tcNew.c_cflag &= ~CBAUD;
                  tcNew.c_cflag |= _baud;
                  tcNew.c_iflag = IGNPAR;
                  tcNew.c_oflag = 0;
                  /* set input mode (non-canonical, no echo,...) */
                  tcNew.c_lflag = 0;
                  tcNew.c_cc[VTIME]    = 0;   /* inter-character timer unused */
                  tcNew.c_cc[VMIN]     = 1;   /* blocking read until 1 chars received */
                  tcflush(fdXBee, TCIFLUSH);
                  tcsetattr(fdXBee, TCSANOW, &tcNew);
                  // Now we need to create our thread for doing the reading from the Xbee
                  pthread_barrier_init(&_barrier, 0, 2);
                  err = pthread_create(&tidXBee, NULL, &XBeeThreadProc, this);
                  if (err != 0)
                      return false;
                    // sync startup
              #ifdef CMDR_USE_SOCKET
                  // Now we need to create our thread for doing the reading from the Xbee
                  err = pthread_create(&tidSocket, NULL, &SocketThreadProc, this);
                  if (err != 0)
                      return false;
                  return true;


              If looking at the code would help, my code is up on github (kurte/raspberry_Pi) project in the library/commanderEx.cpp file.  Again it is modified to be similar to what the Edison Arduino system does for Serial1 in the function void TTYUARTClass::begin( const uint32_t dwBaudRate ) in the file TTYUART.cpp.


              good luck

              • 4. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                Forgot to mention in the above that I use MRAA to configure the IO pins.  Example:

                From my Commander test program:


                char szDevice[] = "/dev/ttyXBEE";
                Commander command = Commander();
                int main()
                    printf("Arbotox Commander XBee Test!\n");
                    // Install signal handler to allow us to do some cleanup...
                    struct sigaction sigIntHandler;
                    sigIntHandler.sa_handler = SignalHandler;
                    sigIntHandler.sa_flags = 0;
                    sigaction(SIGINT, &sigIntHandler, NULL);
                    mraa_uart_context uart;
                    uart = mraa_uart_init(0);
                    if (uart == NULL) {
                        printf("MRAA UART failed to setup\n");
                    // Lets try to open the XBee device...
                    command.begin(szDevice, B38400);


                So on the Edison on an Arduino board this should setup digital pins 0 and 1 to work as a UART

                On the Mini breakout board it should setup MRAA pins 26(J18-13) and 35(J19-8).


                I know that I have tried the commander stuff out on Arduino board and I believe I did some testing on mini board, will be trying it again soon, as soon as I solder in the connectors to the new board.

                • 5. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                  Hi CMata_Intel,


                  I have just verified via datasheet that 115200 8N1 is the right default communication mode for the NXP PN532 Chip's Serial Interface.

                  • 6. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                    As a note: This is what I see if I simply try to read MFD1


                    root@eddy1:~# cat /dev/ttyMFD1



                                                         ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????

                                                                                                                                   ????????????????? ??





                    ???????????0????       ?????????????????????????_?

                                    ??????????????????? ????????????


                    ?                                                                     ??_???????C?




                                                   ?????????????????x???????????????????????????_?????????? ???????????????????

                    ?????????????????????????k????                                                                             ?????????????????????????????????????????




                    ?????????????$?                                               ????

                    ??????????     ??????




                    ?????i???????              ?????????????????????????[???????



                    • 7. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                      Well... I hate to say this, but I hooked up ttyMFD1 to my Mac at 115200 8N1.  The edison transmits/receives  characters wonderfully


                      That means... the PN532 is not acting correctly as far as I can tell.



                      • 8. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                        More info.  The PN532 Breakout board I have has two sets of pins for serial tx/rx.


                        Both sets of pins are connected with a wire (effectively "the same pin").  However, only the pins nearest the PN532 chip itself work with the edison.


                        I wonder if it has anything to do with the extra 3cm of traces.  Is it capacitance? Is it a difference in line length?  Why is this strangeness manifested on the edison and not BBBk or a Mac serial interface? Hmm....

                        • 9. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                          Just wondering, how are you electrically hooking up the sensor to the Edison and/or Mac?

                          On Edison: if you care connecting to pins 0, 1 you would need TTL level signals either 3.3v or 5v depending on jumpers (0 low, 5v high).


                          If connecting to Mac, I assume through some adapter.  Or is there some location on MAC with Serial input.  TTL? or RS232?  Where it uses +- voltages....



                          • 10. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                            Edison -> PN532 - Via Edison Arduino Breakout

                            PN532 -> Mac - Via FTDI USB-RS232 Adapater

                            • 11. Re: Garbage on /dev/ttyMFD1 (Edison + Arduino Breakout)

                              Finally got the schematics of the PN532 Breakout board.   Turns out the FTDI breakout pins has RX and TX reversed (Probably for null modem ease of use).  All is well.


                              Oddly enough, I did try reversing pins earlier but that did not work.  Now it does.  Who knows.


                              CMata_Intel and KurtE, thanks for lending a hand.