This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART echo example

Other Parts Discussed in Thread: EK-LM3S8962, MAX232

I'm trying to use the EK-LM3S8962 UART1 to communicate with a Computer.

First I connected the EK to a MAX232 transceiver and tried to run UART echo example. I use Motocross to receive and send chars at the COM Port.

The example worked fine, but when I made my own UART experimental program, very similar to the example, it didn't work...

After some time of debug I find out that when I call the RIT128x96x4Init (1000000) function, my program works fine and, at the same way, when I erase that function from the UART echo example (erasing, also, all the calls for the OLED), the sample don't work.

Do someone know if there is there any command inside RIT128x96x4Enable that is necessary to the UART to work?

My main function is as shown below (the UARTSend function is copy/pasted from the UART echo example):


SysCtlClockSet ( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );
SysCtlPeripheralEnable ( SYSCTL_PERIPH_GPIOD );
SysCtlPeripheralEnable ( SYSCTL_PERIPH_UART1 );

GPIOPinTypeUART ( GPIO_PORTD_BASE , GPIO_PIN_2 | GPIO_PIN_3 );
UARTConfigSetExpClk ( UART1_BASE , SysCtlClockGet() , SerialBAUDRate , ( SerialNumBits | SerialStopBits | SerialParity ) );

UARTEnable ( UART1_BASE );

// RIT128x96x4Init(1000000);

UARTSend ( (unsigned char *) "A porta serial RS232 esta sendo acessada." , 41 );
while(1) {
*pBufferRX = UARTCharGetNonBlocking ( UART1_BASE );
if ( *pBufferRX != -1 ) {
UARTCharPutNonBlocking ( UART1_BASE , *pBufferRX );
pBufferRX++;
}
}
return 0;
  • I have a new clue: when I change the frequency of the RIT128x96x4Init function to 10000, the program stops working.
  • I don't see any reason why the OLED display settings would interfere with UART1. That may be a side effect of another issue.

    I see a couple of things you should look at.

    UARTCharGetNonBlocking() requires a preceding call to UARTCharsAvail(). Refer to the Stellaris Peripheral Driver Library User's guide for more information on these functions.

    The other thing I noticed was that you're incrementing the pointer pBufferRX without any limits checking. I guess it'll work for a while depending on how much space you've allocated for pBufferRX!

    -- Jon
  • I will take a look at UARTCharsAvail function.

    Thank you for helping!
  • The UARTSpaceAvail function didn't work out...

    There is another clue to solve the problem. When I compile my code with the RIT128x96x4Init function the program transmites data via UART fine, and when I erase it, it doesn't, right?

    But there is another thing: if I download my code without the RIT128x96x4Init function just after I ran the program WITH that function, the program works fine for the first time I run it, but when I reset the program he stop transmitting (but receive ok, as always), even if I shut down the board and turn it on again.

    That leads me to think that RIT128x96x4Init function changes something at the uc's internal registers that make the program to work... And it leads me to think that it isn't a hardware problem.

    I don't think that any other issue is causing this error because the same thing occurs with UART Echo example that comes with the EK... In this example, when I erase the code that initializes the OLED display (and ONLY that code), the Echo program sends data, but the computer gets wrong chars, in PC I get this char "ð" when I send five "p"... how troublesome...
  • I took the uart_echo example from the latest release. I commented out every "RIT..." function call and rebuilt the program. I tested it and the UART echo was still working fine. I was using Teraterm for the PC terminal.

    Is this is what you are saying is not working? If so, then you must have some other subtle difference in your program.
  • I'm guessing that when p.p.santos comments out or removes all the display calls, he inadvertently also comments out something that's not related to the display. Or perhaps he's not commenting out everything related to the display, and something is hanging up because the display init function is not being called.
  • Hi!

    You are right. I got the Echo Example from the Luminary CD and it worked fine when I erase the lines I said before. I must have changed other line so that the program didn't work.

    I think I solve the problem. When I use PLL to clock the uc the UART doesn't transmit correctly. I have to use the crystal itself.

    But I still don't know why, when I call the RIT128x96x4Init function, it works fine even with PLL.

    Thank you all for the attention!!
  • I think there must still be something wrong. The UART should work even when the PLL is used for clocking.