hldswrth
Posts: 108
Joined: Mon Sep 10, 2012 4:14 pm

UART read not working (sometimes)

Mon Oct 22, 2012 8:52 am

I've been struggling with getting serial comms working for a couple of days and so far has not come up with an explanation of the behaviour I'm seeing. I'm hoping someone has a suggestion which can explain the behaviour and also reliably fix it.

I can get my serial transmit and receive code to work if its the first thing I do in my main routine - so there's nothing essentially wrong with the code or the hardware.
However if I put the serial initialisation code after my console init code which sets up the screen and prints an initial line, serial transmit works, but read never receives a character.
If I remove the "printf" from the console init code, i.e. just allocate the framebuffer and clear it, then serial receive works.
If I insert a particular "printf" in the serial init code between setting the registers and setting the GPIO pin functions, serial receive works regardless of when the init code is called.
I'm guessing this has something to do with memory barriers, although an initial attempt to use one made no difference, using the following code:

int name = 0;
__asm__ __volatile__ ("mcr p15,0,%[t],c7,c10,4\n" :: [t] "r" (name) : "memory");

Is this likely to be a memory barrier issue? I'm totally bemused as to why the presence or absence of a printf would prevent receive from working (while transmit always works).

fulvio
Posts: 17
Joined: Tue Sep 25, 2012 5:29 am

Re: UART read not working (sometimes)

Mon Oct 22, 2012 11:19 pm

Hmm, I'm having a similar problem over here:

http://www.raspberrypi.org/phpBB3/viewt ... 0&p=200147

Keep in mind I can always make a serial packet send successfully, however on the receiving Arduino end I always receive a packet with illegal characters instead of the expected text packet.

e.g:

Sent Packet: {power,tv}
Received Packet: ·Á½ÝÉtv}

I cannot for the life of me, figure out why. I've played with different baud rates, bits, parity, etc. Nothing seems to fix the problem.

This is using the UART that I've freed on the Pi, keep in mind it works with with a RS232 USB Breakout Board though.

simong
Posts: 9
Joined: Tue Jul 23, 2013 8:43 pm

Re: UART read not working (sometimes)

Wed Oct 23, 2013 6:42 pm

I am currently experiencing this exact same issue, did you manage to get to the bottom of it, or
does anyone else have any ideas what might be causing this?

This works:

Code: Select all

printf("Waiting for input from UART...\n");
uart_read_char();
printf("Received data!\n");
This does not.

Code: Select all

printf("Waiting for input from UART...\n");
printf("Hello, Pi Forum!\n");
uart_read_char();
printf("Received data!\n");
:shock: :?

(Sorry for bumping such an old thread, but the OP describes my probably exactly! :))

Thanks

Return to “Bare metal, Assembly language”