4 Replies Latest reply on Jun 8, 2015 8:55 AM by juanB

    mraa c++ UART + edison mini breakout.

    juanB

      Hi, I'm new with intel Edison and I'm trying to develop a c++ application to read data received in edison's uart gpio's and write it to console (in the future the data must be filtered and sent via wifi or serial).

       

      I'm working with intel Edison + mini breakout board and I've done all tutorials in order to flash it with last firmware, install drivers and developers kit in pc, connect to pc with putty (microUSB serial port) and I've configured eclipse in order to deploy applications in the Edison (Hello world succesfully run).

       

      Next step for me was update mraa library in windows (for eclipse) and in the intel Edison.

      I think it is correctly updated because it matches every function (for example write, read, setBaudRate...) and previously eclipse nor edison recognize them.

       

      I'm trying to run the example for uart c++ in mraa (https://github.com/intel-iot-devkit/mraa/blob/master/examples/c%2B%2B/Uart-example.cpp) and I'm unable to make it work.

       

      I know I need to see the pin correspondence for mini breakout (https://github.com/intel-iot-devkit/mraa/blob/master/docs/edison.md), but for any reason it doesn't work.

       

      Is it necessary to enable pins in linux with this kind of commands: How to enable PIN0/PIN1 for UART usage (TX/RX)?

       

      For example, if I need to use uart-1-RX (26 in mraa) to 38400 bauds, May be the code this way? I modified the code to read from uart.

       

      About the code:

      1. Is it necessary the second initialisation? (lines 27- 33)

          if yes, why? is it to make correspondance between the pin and a serial tty? How do I know what tty I need to use?

      2. If I run the code below the errors are

      Error while setting up raw UART, do you have a uart?

      terminate called after throwing an instance of 'std::invalid_argument'

        what():  Error initialising UART

      Aborted

      logout

      3. If I run it without lines 27- 33 the errors are:

      Error initialising UART, likely invalid platform config

      traza 1

      Segmentation fault

      logout

       

        

       

       

      #include <unistd.h>
      #include <iostream>
      #include <exception>
      
      
      #include "mraa.hpp"
      
      
      int main() {
          //! [Interesting]
          // If you have a valid platform configuration use numbers to represent uart
          // device. If not use raw mode where std::string is taken as a constructor
          // parameter
      
      
        char array[255];
        //char * array;
      
      
          mraa::Uart* dev;
          try {
              dev = new mraa::Uart(26);
          } catch (std::exception& e) {
              std::cout << e.what() << ", likely invalid platform config" << std::endl;
          }
         
          try {
              dev = new mraa::Uart("/dev/ttyACM0");
          //dev = new mraa::Uart("/dev/ttymcu0");
          } catch (std::exception& e) {
              std::cout << "Error while setting up raw UART, do you have a uart?" << std::endl;
              std::terminate();
          }
      
      
          if (dev->setBaudRate(38400) != MRAA_SUCCESS) {
              std::cout << "Error setting parity on UART" << std::endl;
          }
         
          if (dev->setMode(8, MRAA_UART_PARITY_NONE, 1) != MRAA_SUCCESS) {
              std::cout << "Error setting parity on UART" << std::endl;
          }
         
          if (dev->setFlowcontrol(false, false) != MRAA_SUCCESS) {
              std::cout << "Error setting flow control UART" << std::endl;
          }
         
      
      
          while(true){
               dev->read(array,255);
               std::cout<<"-> "<<array<<std::endl;
          }
      
      
          //dev->writeStr("Hello monkeys");
          //! [Interesting]
          delete dev;
          return MRAA_SUCCESS;
      }
      
      

       

      Please, can  someoneguide me through serial configuration?

      Thank you for your support!

        • 1. Re: mraa c++ UART + edison mini breakout.
          arfoll

          Ask for mraa::Uart(0) not 26. If you do a raw init then you won't have the muxing done for and obviously your device node needs to exist/be valid.

          • 2. Re: mraa c++ UART + edison mini breakout.
            juanB

            Thank you for your answer arfoll.

             

            It's true that it seems to work with Uart(0), but I will need to be able to use all serial ports and I still don't know how to do it.

             

            If I configure by console that muxing I'll be able to use uart(26)?

             

            Which serial port is Uart(0), the usb one?

             

            How can I configure the port on the GPIOs, for example if I need to use UART-1 (26 for rx and 35 for tx in mraa)?

            Do I need to configure it in the linux console in order to create files and do that muxing first?

             

            I'll apprecite a lot an example, or some tutorial or link where I can read how to do the whole the process.

            I searched a lot, and found fragments of info but I couldn't fix all the parts in order to find out the whole process.

             

             

            Thank you very much for your help.

            • 3. Re: mraa c++ UART + edison mini breakout.
              arfoll

              Call getDevicePath() or mraa_uart_get_dev_path(dev) to find out the linux path. /dev/ttyMFD1 is '0' and it's the uart connected to the arduino breakout via pin 0/1 which is also called UART-1. You don't need to set any muxing, mraa does that all for you. The example on github is literally all you need.

               

              The other serial ports for example the USB one has no muxing so you can just use mraa::Uart("/dev/xxx"). The other uarts provided from the SOC directly are not usable from userspace since one is for MCU comms and the other for your console. You can obviously override the defaults and use mraa 'raw' mode, again I dont believe they are muxed at all.

              • 4. Re: mraa c++ UART + edison mini breakout.
                juanB

                It finally worked, you were right!

                 

                So the available serial ports are the one from the usb, uart-1 and uart-2?

                 

                Thank you!