Community
cancel
Showing results for 
Search instead for 
Did you mean: 
CBrou1
New Contributor I
1,642 Views

I2C-6 and UART-0 incompatibility ?

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

# 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

9 Replies
CBrou1
New Contributor I
74 Views

I made a test with an alternate I2C channel and got the same problematic result.

The mraa documentation mentions that channel 1 is also available on SoC pins and can be used with the proper breakout stacked with the processor (http://iotdk.intel.com/docs/master/mraa/edison.html http://iotdk.intel.com/docs/master/mraa/edison.html) . I don' t have the necessary break out but I did try opening channel 1 instead of 6 in the code ... and the result is the same, the serial connection is lost. I also tried initializing I2C first and then the UART. In that case, the UART just doesn't produce any character.

Sergio_A_Intel
Employee
74 Views

Hi CABrouwers,

What image version are you using? What Eclipse and mraa versions are you using? We'd like to replicate this issue and see if we obtain the same results. Are there any other details of your configuration we need to know so we can replicate?

Sergio

CBrou1
New Contributor I
74 Views

Sergio,

 

Thanks for looking into this.

Here are the details of my configuration:

Eclipse Version: Luna SR2 (4.4.2) Build id: M20150204-1700

Linux version 3.10.17-poky-edison+ (sys_dswci@tlsndgbuild004) (gcc version 4.9.1 (GCC) ) # 1 SMP PREEMPT Fri Jun 19 12:06:40 CEST 2015

 

Regarding MRAA, I am not sure. It is whatever was came with the configuration or was installed automatically.

 

The only other thing to note about my configuration is that I had troubles establishing a serial putty connection when I took the board out of the box.

(see my first post ). I was able to get to shell through IP over USB and later wifi but never with a simple direct serial link as described in the set up procedure. However I used the serial port in my projects since and always without any problem.

I will give you direct access to the device and an my configuration in a private message.

Sergio_A_Intel
Employee
74 Views

Regarding the mraa version if you are using the latest image where the output of configure_edison –version is 159.devkit then you can check the mraa version with opkg list-installed mraa.

The issue with establishing a serial connection out of the box seems strange. Have you followed these steps to configure https://software.intel.com/en-us/get-started-edison-windows-step3 IoT - Step 3: Set up a serial terminal | Intel® Developer Zone ? Make sure you are powering your board correctly and if possible use two USB cables.

Now, run the code again and see if there is any change in the serial connection after initializing I2C. Just to check, have you made any GPIO configurations that may conflict with I2C?

Sergio

CBrou1
New Contributor I
74 Views

Today, I received a new Edison, flashed a fresh image, ran my test code ... and go the exact same problem.

Btw the mraa version i am using is 0.9.0

Also, I have not tinkered with GPIO settings, the two SoCs are running in their original configuration.

So either there is a defect in my arduino board or some weird bug in my toolchain ... or it is a bug in the SoC or the mraa library.

Have you had a chance to try reproducing the issue ?

Sergio_A_Intel
Employee
74 Views

Not yet, I will make some tests and post my reply here soon.

Sergio

Sergio_A_Intel
Employee
74 Views

We were able to use i2c and UART at the same time. Unfortunately, we don't have the sensor you're using. We setup an I2C RGB LCD and sent data to Uart at the same time without issues.

We used the example codes from the following links to make a single code to test.

https://github.com/intel-iot-devkit/mraa/blob/master/examples/c%2B%2B/Uart-example.cpp https://github.com/intel-iot-devkit/mraa/blob/master/examples/c%2B%2B/Uart-example.cpp

https://github.com/intel-iot-devkit/upm/blob/master/examples/c%2B%2B/jhd1313m1-lcd.cxx https://github.com/intel-iot-devkit/upm/blob/master/examples/c%2B%2B/jhd1313m1-lcd.cxx

We tested this using:

root@Edison-ICS01:~# cat /etc/version

weekly-159.devkit-2.0

Sergio

CBrou1
New Contributor I
74 Views

Sergio,

Thanks for running this test. It seems that you were trying to write to the UART, while my issue is with reading from UART. I think it makes a difference because the read function must use hardware interrupts. I suspect that, if there is really an issue, it is a with the use of interrupts in the Mraa library. I found an simpler test procedure using a loop back on the serial port. I ran it on two different boards with two different edison SoC and got the same issue again. I will post it for other to try.

Sergio_A_Intel
Employee
74 Views

Can you post this new procedure you mentioned in the previous post? We'd like to test it and see if we get the same results.

Sergio

Reply