2 Replies Latest reply on Aug 3, 2015 11:31 AM by ConstantinS

    Reading From UART - Edison/UbiLinux

    ConstantinS

      All,

      I have an Edison stack with Sparkfun's base and GPIO board and battery board. I am attempting to use the GPIO pins 128,129,130, and 131 for rs232 with hardware control flow. I have looked through the website many times and am still unable to receive data. I send data just fine however.

       

      Some Facts:

      1. My oscilliscope shows me I'm sending data on the TX line and receiving data on the RX line
      2. When not connected to the other device, the tx line stays blank with my software blocked on the flush command. Once connected, my software unblocks and sends no problem.
      3. How to enable PIN0/PIN1 for UART usage (TX/RX)  Doesn't seem to apply to me:
        1. I do not have devices gpio214, gpio249 gpio217, gpio248, gpio216 - echoing these numbers to export returns "no such device"
        2. "echo 131 > /sys/class/gpio/export 2>&1" returns "device busy" - same with "130"
        3. I have checked the mode1 on pinmux for both 130 and 131. I have made sure the directions are also correct.
      4. My loop back test also fails. I see it send data out but my code doesn't read anything (with a blocking a call)

       

      Does anyone have any suggestions? I'm out of ideas.

       

      Below is my loopback test code:

       

      #include <mraa.h>

       

      int main(int argc, char * argv[]) {

      char* board_name = mraa_get_platform_name();

      fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name);

       

      mraa_uart_context uart;

      //uart = mraa_uart_init(1);

      uart = mraa_uart_init_raw("/dev/ttyMFD1");

       

      if (uart == NULL) {

              fprintf(stderr, "UART failed to setup\n");

              return EXIT_FAILURE;

          }

      printf("Device path: %s\n", mraa_uart_get_dev_path(uart));

       

      mraa_uart_set_baudrate(uart, 57600);

      mraa_uart_set_mode(uart, 8, MRAA_UART_PARITY_NONE, 1);

      mraa_uart_set_flowcontrol(uart, 0, 0);

      mraa_uart_set_timeout(uart, 0, 0, 0);

       

      char output[] = "Hello Mraa!";

      mraa_uart_write(uart, output, sizeof(output));

      mraa_uart_flush(uart);

       

      char dataBuf[1024];

      //while(mraa_uart_data_available(uart, 100)) {

      int dataAmount = mraa_uart_read(uart, dataBuf, 1);

      printf("Read %d bytes\n.", dataAmount);

      //}

       

      mraa_uart_stop(uart);

       

      mraa_deinit();

      }

        • 1. Re: Reading From UART - Edison/UbiLinux
          PabloM_Intel

          Hi ConstantinS

           

          Have you seen this thread https://communities.intel.com/thread/67408? another user had a similar issue trying to work with hardware flow control. Apparently the “device bus” error appears because the GPIO is already exported, so it seems that it has already been set. I also suggest you to ask the guys at Emutex, they are the ones in charge of the Ubilinux image so they can provide a more accurate answer.

           

          Regards,

          PabloM_Intel

          • 2. Re: Reading From UART - Edison/UbiLinux
            ConstantinS

            All, it turns out the gpio pin on my Sparkfun GPIO board was bad. I purchased a new gpio board and everything is working as expected. To discover the bad pin, I did the following tests:

             

            1. Set the CTS pin low. (connect to ground)
            2. Connect the RX and TX pins for a loopback test and open a serial console using ttyMFD1
            3. Press keys on the keyboard, if you see them echoed (with local echo off) your pins are fine
            4. If not, let's turn it into a regular gpio pin
              1. sudo su
              2. echo mode0 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux
              3. cd /sys/class/gpio/gpio130
              4. echo out > direction
              5. echo 1 > value
              6. echo 0 > value
            5. For 5 and 6 above, use an oscilliscope or voltmeter to check the pins voltage, you should be able to change it. If you cannot, there's a good chance it's broken. Use gpio131 for the TX pin
            6. If those work:
              1. echo in > direction
              2. Ground the pin, and cat value, you should see 0
              3. Raise the pin (connect to the 3.3v) and you should see 1 NOTE THAT THIS IS FOR THE SPARKFUN GPIO BOARD WHICH HAS A LOGIC LEVEL, THE EDISON TYPICALLY WORKS ON 1.8V
            7. If you have no response, your sparkfun board may be broken.