1 Reply Latest reply on Apr 5, 2016 10:17 AM by Intel Corporation

    How to configure UART on Gen 1 to read data from Launch Pad using SerialPort.js ?

    Skywatermelon

      I am trying to send serial information from a Texas Instruments Launch Pad (Arduino Compatible) to a Gen 1 Intel Galileo which is running Linux and Node.js with a SerialPort.js module included to read the received UART data. The transmit pin on the Launch Pad is connected to the Rx (Pin 0) of the Galileo. The Galileo is to act as a web server and the data to be sent is simply 3 bytes of data with a terminating "\n" at the end of each transmission to tell the server that it is the end of the data.

       

      Here are two functions that I wrote for the Launch Pad that places the information in to the transmit buffer to be sent. Testing the output of the UART on the launch pad shows that the information is coming out correctly.

       

      void uartCHAR(int txChar)
      {
          while (!(IFG2 & UCA0TXIFG)); //Wait for the transmit buffer to be ready
          UCA0TXBUF = (char)txChar; //Put integer value in to UART transmit buffer in character format
      }
      
      
      void uartTransmit(int tx)
      {
        P1OUT |= REDLED; //Turn on Red LED
        unsigned int byteSelect = 0xFF00; //Declare value used to isolate each byte
        unsigned int byteHold = 0; //Declare varible to hold isolated byte
        unsigned char sendByte = 0; //Declare a variable to hold the byte to be transmitted
        int k; //Declare a variable to be used in the for loop
        for (k = 1; k>=0 ; k--) //Cycle through the code twice
        {
      
        byteHold = byteSelect&tx; //Isoltate each section of 8 bits in the and store in byteHold
        byteHold >>= (8*(k)); //Shift the data down to the lowest byte position
        sendByte = byteHold;
        uartCHAR(sendByte); //Pass sendByte in to the uartCHAR function
        byteHold = 0;
        byteSelect>>=8; //Shift the byte selector to the next section of 8 bits
        }
        P1OUT &= ~REDLED; //Turn off Red LED
        uartCHAR('\n'); //Send symbol to indicate to the parser that the end of the message has arrived
      }
      

       

      Here is a bash script that I found to configure the UART before running the JavaScript code to turn on the server functions.

       

      #!/bin/bash
      
      # Initialize sysfs to use the uart on pins 0 and 1 as /dev/ttyS0:
      echo -n "4" > /sys/class/gpio/export
      echo -n "40" > /sys/class/gpio/export
      echo -n "41" > /sys/class/gpio/export
      echo -n "out" > /sys/class/gpio/gpio4/direction
      echo -n "out" > /sys/class/gpio/gpio40/direction
      echo -n "out" > /sys/class/gpio/gpio41/direction
      echo -n "strong" > /sys/class/gpio/gpio40/drive
      echo -n "strong" > /sys/class/gpio/gpio41/drive
      echo -n "1" > /sys/class/gpio/gpio4/value
      echo -n "0" > /sys/class/gpio/gpio40/value
      echo -n "0" > /sys/class/gpio/gpio41/value
      stty -F /dev/ttyS0 raw
      stty -F /dev/ttyS0 9600
      

       

      Here is the section of the JavaScript code using Node.js and SerialPort.js to listen for data on the UART.

       

      var express = require('express');
      var app = express();
      var io = require('socket.io').listen(app.listen(4000));
      var com = require("serialport");
      
      app.get('/', function(request, response){response.sendfile(__dirname + "/home.html");});
      app.use('/static', express.static(__dirname + '/public'));
      
      var activeClients = 0;    
      
      io.sockets.on('connection', function(socket){clientConnect(socket);});
      
      var serialPort = new com.SerialPort("/dev/ttyS0", {
          baudRate: 9600,
          dataBits: 8,
          parity: 'none',
          stopBits: 1,
          flowControl: false,
          parser: com.parsers.readline("\n")
        });
      
      serialPort.on('open',function() {
        console.log('Port open ');
        console.log(process.argv[0] + " " + " " + process.argv[1]);
      
      serialPort.on('data', function(data) {
            console.log("Data recieved: ");
            console.log(data.toString());
         io.sockets.emit('heartUpdate', {heartcrc:data});
            emitHeartRate(data);
        });
      serialPort.on('close', function () {
            console.log('Port close');
        });
      serialPort.on('error', function () {
            console.log('Error');
        });
         
         
      });
      

       

      When the server code runs it simply waits a few moments, prints the "Port open" Message to the screen and prints the arguments as well but there is never any data. If anyone could suggest why this might not be working I would really appreciate it.