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

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

    pctj101

      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

      and

      https://communities.intel.com/message/265411   

       

      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)
          CMata_Intel

          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?

           

          Regards;

          CMata

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

            CMata_Intel,

             

            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:

             

            07F403F603F903F201FC0BB0FF01FD1BFC00F803F40FEC03FC03FC03FC00B001FC02F603FD03FE01EC03FC02F403F403B402F807F401E903F400F403F403FC01F602FD17B000F403F401D003F002FC03FD03F402F4FF0BFC03F003FC0BF402FD00F403F403B000FC11F0FF03FC03F403FC02F413F601F403FC03FF03EC03FE03FE03FC03FD03FC03F403FD13F40BFE03F802ED03F403FE03ED03FC03FE09F003F000F401FC00F602FF03FE03B000F803FC02F403F401F603F0FF03FD03FC01FD03FE03FC03FC13F613FE03F900FA03F005FC03F001F403E003F603F403FA03F602E000F403F401ED03FC00FC01FE13FC03E607FE03FC00F602FF00F003FD03F802F003F103FF03FE00F403B401F403FE02FD03F403F413FE03FD00FC01F81BE103F803B003F403F403F403F60BF403FF03F403FC03F001FC03FC00F803F403F413F60BF600D000ED03F203F403FC01EC01FF03E403E803F403F403FC03F401FD03FC00FA03FE00FC03F800F400FE03FC00F207F401FC00FD03FE01F600F603F401F601F200F403FE03FD03F602FA03F002F601F403F900FC03FC03F403F803F401FC03F002F803F402F800F402F003FE03FE07FC03FE03FC03F601FD03FD03FC03F803F201F803F003FE01FC13F803FE00FC00FE02F800FF0BFE03FF00FF03F602F403FC01F601F403F403F602FE02FC03FE13FC02FA03FE03FC00FC03FD01FA03FF03FE02FC03FE00FC03FD02FC02F601FF00F401FC03FC02F403F403FC03F403FF03FD00F400F601F403F603FC13FD0BF803FD01F203F403ED07F603F801FA01F803B403F802F800F403F802FC00FF02F801F403FC03F600FE00F403E800F803AC03F003FF03F000FF00E201F403FC02FE02FE03F003FC0BF803F013FC03F401FC03F603F003DA03F401B40BF803F400F403F401B0FF03F40BFE0BFC03FC05F403E003FD01FC03FC00FF03FC13E0FF01FE01F003FF03F603FC03B4FF03FE00FC03D007F400F417FD03FE01F400F003F002FF03FC03FE03FE03FC02F813E903F403FD03FC03FD03E502F403FD03F403F803F003FC02F400E903FC00FE03FC03F602F001FC0BE803FE01F003FC03F001FE03F401FD00FE00FE0FF903FD03F400FE02FE03FE03FD0BFC03F003FC03F400FC01FC00FF02FC03FE03FC01F603FC03F400FE00FE01FC02FD01F800FC03FD03E803FF02F401FE02FC05FC01F603FA00A001F60BFA02B401E401F603FC03F002F403F400B403F002E401F803FC03FC01FE01A003F00BFE03ED03


            On a second run I get:

             

            FC03FE02F603F203FC00E403FE01F0FF03E400FC01FC00F003F203F401F602FC03FA03F401FD03FD03F601F403FC03FA01FC03FE03F401F001FF01F902F002FC00FD00E003FE13F493F401FE03FE03F80BF413E403F80FFE01FC02FC03F605F901F402FE03F403F403F200F403FD07F403FE00F20BF000F203FC01F401F413FD03F803F403FF03FC03F403E903F003A001F801F603FE07F401F00BF403F80BFE13FC03FC0BFD03FE00F813F003F403FD03FE01FD0BFE03FE00F402FC0DFC17BC03F003B403FD03ED03FC03FC02FE03FE03F803FE01F401FC03FD13B013FD03F603ED00FC13F403A003FC13A400F603C0FF17FD01B0FF03D803FD02FC01F002FC03EF03FF03F403FC03FC03F403F403FE0BF81BFD02FC0BFA06F001F413F603F603FC02B0FF03FC03C502F403EC03F400F913EA01FE02F403F401FE03F60BFC07FC00F003A403FF03F603F803FE00FC13FC03FE07FC02FC03FC00F403E803F401FC03FE03ED03F403F403E801F400C803F401FC03E901F403FD03F402E801F403E803F403E60BF907FD0BFC03F003EC00F402F900F801FD02FE01FE03F003FC03B400FC03F003FC03EF06F60BF403F603FC02F403F600F000F800FD03FF03FE03EC03FE02FE00FC03FC00FC02F003FE03FE03FE01F603FE03F403FC01F003FB03FC03F409F403FE00F200F401FC01F803FC01FC00FE03FC03F800F403F401FC03F603F003FF00EC03FC01FC01FD03FC02FE02FC03E003F903F401FE00F80BFE03F803F400FD00F607FC03F400F001F402FD03FE03FC17F603FC03FC02FC02FF03FF00F402FF03FC01F600FC00FE13FA02F603F602FE03FA02FD03FE13D000FD01F800FC01F002FE02FD01F003F603FC00B401FC00F000FC03FC0BF003FC



            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)
              KurtE
              
              

              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))
                  {
                      perror("tcgetattr()");
                      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
                  pthread_barrier_wait(&_barrier);
                  
              
              #endif
              #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;
              
              #endif
              
              
                  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)
                KurtE

                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;
                    sigemptyset(&sigIntHandler.sa_mask);
                    sigIntHandler.sa_flags = 0;
                
                    sigaction(SIGINT, &sigIntHandler, NULL);
                
                    mraa_uart_context uart;
                    mraa_init();
                    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)
                  pctj101

                  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)
                    pctj101

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

                     

                    root@eddy1:~# cat /dev/ttyMFD1


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

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

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

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

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

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

                            ?

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

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

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

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

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

                    ?/?????????

                                ????6???????????

                                                ???

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

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

                                                  ?????????

                                                           ?????

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

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

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

                              ???

                                 ????

                                     ??????????

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

                                 ???O??????????????????????????

                                                               ????????????????????????????????????^C

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

                      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.

                       

                      Sigh....

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

                        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)
                          KurtE

                          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....

                           

                          Kurt

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

                            Edison -> PN532 - Via Edison Arduino Breakout

                            PN532 -> Mac - Via FTDI USB-RS232 Adapater

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

                              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.