9 Replies Latest reply on Feb 18, 2016 7:31 AM by Intel_Alvarado

    I2C-6 and UART-0 incompatibility ?

    CABrouwers

      It seems that initializing I2C channel 6 disables receiving data on the base UART (mraa 0  - "/dev/ttyMFD1).

      My set up is : Edison Arduino Board, Eclipse, C++ and mraa.

      I have a device (RPLidar) attached to the serial port and it continuously sends data. It is works very well when I don't use the I2C port.

      I want to add I2C devices but I noticed that that, soon after  I initialize I2C channel 6, the UART stops receiving data.

      On the other hand the I2C port works well when the UART is not in use.

      Is there some incompatibility between the two ports ?

      I have written the following test code. It initializes the serial device and starts receiving data. After a delay, it also initializes the I2C port.

      In every test I run, very soon after initializing the I2C port, the serial communication stops (I assume the short lag is due to the time needed to consume the remaining buffer data).

       

      #include <iostream>
      #include "mraa.hpp"
      using namespace std;
      
      int main() {
      
        //set up serial communication with sensor (RPLidar);
        mraa::Uart* LidarUart = new mraa::Uart(0);
        LidarUart->setBaudRate(115200);
        LidarUart->setMode(8, mraa::UART_PARITY_NONE, 1);
        LidarUart->setFlowcontrol(false, false);
      
        //Raise pin 8 to enable sensor (controls Lidar rotation);
        mraa::Gpio* MotorControl = new mraa::Gpio(8, true, false);
        MotorControl->dir(mraa::DIR_OUT);
        MotorControl->write(1);
      
        //send serial command to sensor to initiate data transmission
        unsigned char command[2] = { 0xA5, 0x20 };
        LidarUart->write((char *) command, 2);
      
      
        mraa::I2c* i2c;
      
      
        //various informational variables for monitoring test
        bool onetime = true;
        time_t now;
        time_t start;
        time_t lastchar;
        time_t startI2C;
        int numchar = 0;
        time(&start);
        cerr << "Starting" << endl;
      
        for (;;) {
      
        //if serial char available read and discard.
        if (LidarUart->dataAvailable()) {
        char c;
        LidarUart->read(&c, 1);
        //monitoring purpose only
        ++numchar;
        time(&lastchar);
        }
      
        time(&now);
      
        //I2C port initialized after 45 second of operation
        if (onetime && difftime(now, start) > 45) {
      
        //initialize I2C port
        i2c = new mraa::I2c(6);
      
      
        cerr <<endl<< "Opening I2C port" << endl;
        onetime = false;
        startI2C = now;
      
        }
      
      
        //Test completed after 90s
        if (difftime(now, start) > 90) { break;}
      
      
        }
      
      
        MotorControl->write(0);
        cerr<<"-----------------------------------------------------------"<<endl;
        cerr<<"Start:"<<difftime(start, start)<<endl;
        cerr<<"Last serial received:"<<difftime(lastchar, start)<<endl;
        cerr<<"I2C Started:"<<difftime(startI2C, start)<<endl;
        cerr<<"Stop:"<<difftime(now, start)<<endl;
        cerr<<"character received after I2c Started:"<<numchar<<endl;
        cerr<<"---
      
      
      -------------------------------------------------------"<<endl;
      
      
        return 0;
      

       

       

      Here is a typical output:(the numbers indicate the number of second after the start - except the last one, which is a number of char).

       

      Starting


      Opening I2C port

      -----------------------------------------------------------

      Start:0

      Last serial received:46

      I2C Started:46

      Stop:91

      character received after I2c Started:4690

      -----------------------------------------------------------

      logout