This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to send serial data to PC

I am trying to send the data to UART1 in LP2148. Given below is the code.
But the data displayed is only some junk (mainly ???? is displayed). I am not able to makeout the problem.
The terminal software is configured at 9600 baud. pclk is 15 MHz.

#include <lpc214x.h> //Includes LPC2148 register definitions

#define Fosc 12000000
#define Fcclk (Fosc * 5)
#define Fcco (Fcclk * 4)
#define Fpclk (Fcclk / 4) * 1

#define UART_BPS 9600 //Set Baud Rate here

const unsigned char SEND_STRING[] = "Nex Robotics PVT LTD\nARM7 LPC214x Development Board\nCommunication Test\nSend any character to continue\n";
const unsigned char SEND_STRING1[] = "Test Passed\n";

void Delay_Ticks(unsigned int Delay) //Function to generate finite delay
{ unsigned int i; for(; Delay>0; Delay--) for(i=0; i<50000; i++);
}

void Init_UART1(void) //This function setups UART1
{ unsigned int Baud16; U1LCR = 0x83; // DLAB = 1 Baud16 = (Fpclk / 16) / UART_BPS; U1DLM = Baud16 / 256; U1DLL = Baud16 % 256; U1LCR = 0x03;
}

void UART1_SendByte(unsigned char data) //A function to send a byte on UART1
{ U1THR = data; while( (U1LSR&0x40)==0 );
}

void UART1_SendStr(const unsigned char *str) //A function to send a string on UART1
{ while(1) { if( *str == '\0' ) break; UART1_SendByte(*str++); }
}

int main(void)
{ PINSEL0 = 0x00050000; // Enable UART1 Rx and Tx pins PINSEL1 = 0x00000000; PINSEL2 = 0x00000000;

Init_UART1(); UART1_SendStr(SEND_STRING); while((U1LSR&0x01)==0); UART1_SendStr(SEND_STRING1); while(1) {

} // return(0);
}

  • Why your "times 1"?

    #define Fpclk (Fcclk / 4) * 1
    

    And never play with #define expressions without enclosing them inside parentheses.

    And why not read the posting instructions for source code? It makes it so much easier to read your code.

    What actions did you take to verify your baudrate?

  • Thanks for your suggestion. I am new to Embedded programming. I took the code came with one of the development boards directly. So I am also not sure why multiply by 1 is used in #define Fpclk (Fcclk / 4) * 1.

    How to verify the baud rate without connecting to another device? In host side I have terminal tool and also verified in device manager.
    PCLK is set to Fosc/4 and I can see that in start up
    VPBDIV_SETUP EQU 0
    VPBDIV_Val EQU 0x00000000 ; 0==>cclk/4, 1==> cclk , 2==> cclk/2

    I will follow instructions from next post onwards.

  • How to verify the baud rate without connecting to another device

    easy, send a constant stream of 'U' (uppercase U) and your scope will show a square wave with a frequency of exactly 1/2 the baudrate

  • Problem seems to be something else. If I use USB boot loader, I have this problem. If I use serial boot loader, same code works. Not sure where the problem could be.
    Also I do not have oscilloscope with me. So I have to debug only using serial port/LEDs/LCD.

    The divisor (U0DLL) for baudrate is correct and it displayed the character 'a' (97) in LCD.

    The data is getting sent to the seral port. Because in main program, statement while((U1LSR&0x01)==0); is coming out. But only ??? is displayed still.

  • easy, send a constant stream of 'U' (uppercase U) and your scope will show a square wave with a frequency of exactly 1/2 the baudrate

    That's a very useful test. But be careful, it's only like this under certain conditions; e.g., change to 8 data bits, fixed parity, two stop bits and there will be some deviation.

  • Either way, measuring bit timing is the way to confirm, and you use a data pattern that facilitates that, if you're not stuck using stone tools and rocks for debugging.

    Review the clocks and register setting for other related buses to understand the behaviour of the usb vs serial boot.

  • If playing with boot loaders, then the PLL may not be configured in the way you thought in the processor - the USB interface has very specific requirements about clock speeds so an USB boot loader has to do much more work with the clocking than a serial-only boot loader.

    Is your own code robust enough to be able to switch from PLL to RC clock, deactivate a running PLL, reconfigure the parameters of the PLL and spin it up again and after it has synchronized switch back to the PLL as clock source?