Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9867 Discussions

UART Read Problem

idata
Community Manager
2,316 Views

I tried to read data from the UART with an Loop-Back test.

I used this code:

But it did not work...

The mraa version is 0.7.3 (Programming in Eclipse IDE, using arduino beakout board)

the intel edison does nothing if I try to read data and seems to be blocked at the read function.

Had anyone success in the loopback test?

Flo1991

12 Replies
MGilm
New Contributor I
173 Views

I have used loopback in the past, but have no direct experience with loopback in this environment, so I might ask/suggest some unrelated things...

1) Does this loopback test require an actual physical (wired) connection between RXD and TXD?

If so have you done this? Can you scope this line to see if data is coming out?

2) Does the code require some kind of a functioning "hardware handshake" (CTS/DTR etc.) connection?

Mike

Carlos_M_Intel
Employee
173 Views

Hi Flo1991,

Have you been able to run the code successfully?

You mentioned you are using the 0.7.3 MRAA version, the latest one is the 0.9.6, have you tried to update the library?

Also, what do you exactly mean with "it did not work"? Is there an error message, wrong data, no data…?

Regards,

Charlie

idata
Community Manager
173 Views

Sorry for this less information, now I have some details:

-loop back is done by connecting TX with RX

-software is compiled

-no error message

-if I debug the programm it blocks at reading data (endless loop..)

Further analysis showed, if data is written, something strange happens:

->UART sends some random data, UART sends the message, UART sends random data after the message until mraa_uart_stop(uart); is reached

->no data is read in the buffer and the function blocks, so always random data is on the bus?!?-.-

->data block size seems to be at least 2 bytes (I suppose mraa_uart_write adds a \n or transmits the string ending ?!?)

The code I use:

# include

# include

# include "mraa.h"

int main(int argc, char** argv)

{

printf("Start\n.");

char dataBuf[1];

mraa_uart_context uart;

uart = mraa_uart_init(0);

if (uart == NULL) {

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

return EXIT_FAILURE;

}

//configure

mraa_uart_set_baudrate(uart, 57600);

mraa_uart_set_mode(uart, 8, MRAA_UART_PARITY_NONE, 1);

//try to write

char buffer[] = "1";

mraa_uart_write(uart, buffer, sizeof(buffer));

mraa_uart_flush(uart);

//try to read

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

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

mraa_uart_stop(uart);

mraa_deinit();

return EXIT_SUCCESS;

}

Did anyone get UART work using mraa 0.7.3?

If the version 0.9.6 is neccessary, how can I include this version directly in the kernel using bitbake?

Flo1991

idata
Community Manager
173 Views

New information:

seems to be no random data:

using an FTDI I get the following data:

0x00 (change UART Baudrate)

0x33 (I sent char buffer[] = "3"; looks good)

0x00 (Maybe the string ending, don't know)

now I get 0x335E40 repeated around 1365 times

after that I only get 0x07 until forever...(until mraa_uart_stop(uart); ->that does not happen because mraa_uart_read is blocking...)

Detailed Debug Information:

in the disassembly the line

4a491c2c: int $0x80

starts the transmission, the data is sent as described above

//Some more lines of the disassembly:

4a491c04: neg %eax

4a491c06: mov %eax,%gs:(%ecx)

4a491c09: or $0xffffffff,%eax

4a491c0c: ret

4a491c0d: xchg %ax,%ax

4a491c0f: nop

4a491c10: cmpl $0x0,%gs:0xc

4a491c18: jne 0x4a491c37

4a491c1a: push %ebx

4a491c1b: mov 0x10(%esp),%edx

4a491c1f: mov 0xc(%esp),%ecx

4a491c23: mov 0x8(%esp),%ebx

4a491c27: mov $0x4,%eax

4a491c2c: int $0x80 <<<<start transmission of UART data

4a491c2e: pop %ebx

4a491c2f: cmp $0xfffff001,%eax

4a491c34: jae 0x4a491c63

4a491c36: ret

4a491c37: call 0x4a4ad510

Any suggestions? Hints? Whatever?

Flo1991

Carlos_M_Intel
Employee
173 Views

Hi Flo1991,

I suggest you to first update the MRAA version with:

echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586 http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf

opkg update

opkg install mraa

Then, run the code you were using, I ran it and I obtained the following:

root@edison:~# ./test

Start

.Read 1 bytes

In order to include the latest mraa version into a custom image, I suggest you to use the latest source files, the middleware should allow you to include the library into the built.

Please try updating the library first so we could see if this fixes your problem. Let us know about the outcome in order to help you to include the library into the built or to find another alternative for the problem with the UART.

Regards,

Charlie

Matthias_H_Intel
Employee
173 Views

re bitbake for latest mraa version: you certainly could bitbake. Just grep latest recipe from http://git.yoctoproject.org/cgit/cgit.cgi/meta-intel-iot-devkit/tree/recipes-devtools meta-intel-iot-devkit - Intel IoT Developer Kit metadata. However, I'd also recommend using the way suggested by CMata_Intel

re the UART / FTDI issues: it's not completely clear what you're trying to achieve:

- which baseboard do you use?

- do I get it right that you're using a USB FTDI serial dongle?

- how does your loopback setup look like?

Sergio_A_Intel
Employee
173 Views

Hi Flo1991,

Were you able to follow CMata's and mhahn's suggestions? What were the results of your tests? Let us know if you still need help with this thread.

Sergio

idata
Community Manager
173 Views

Sorry for the late reply, I have been on holidays

Updating the mraa lib solved the problem, thank you

I already build some images using bitbake refering to http://download.intel.com/support/edison/sb/edisonbsp_ug_331188007.pdf http://download.intel.com/support/edison/sb/edisonbsp_ug_331188007.pdf

but don't know how to include the newest mraa version, so some further help would be nice

Flo1991

Sergio_A_Intel
Employee
173 Views

To include the latest recipe you can look at section 4.3 of the BSP you posted, only instead of adding opencv, add mraa. In step 2 and 3 you have to make the appropriate changes to configure the paths and dependencies correctly. Make sure to add all the dependencies needed. You can use menuconfig to see the list of dependencies needed for the build to work. Let us know if you have any specific questions about these steps. If you receive any errors please add them to the case.

Sergio

idata
Community Manager
173 Views

Ok I will try this as a next step but sadly my linux build environment machine crashed so it will take some time....

Furthermore I would like to use the newest source files for yocto 3.0

I am going to post the results if I have updates

Flo1991

idata
Community Manager
173 Views

Do you have any updates? Have you used the newest image with your project?

 

 

Sergio

 

idata
Community Manager
173 Views

Using the newest available image (that includes newer version of mraa) the uart communication is working

Flo1991

Reply