We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
HELLO
I TRANSMITTED THE DETA THROUGH UART 2 IN LPC 1768 BUT STILL I CHEK ALL RAGISTERS AND ALSO DATA SHEET
I TRANSMITTING DATA UART TO UART HELP OF MCP BUT STILL IT IS NOT TRANSMITTED ACCORDINGLY SO PLZ HELP ME I SEND A FULL CODE
#include <lpc17xx.h>#define THRE (1<<5) //Transmit Holding Register Empty#define MULVAL 15#define DIVADDVAL 2#define Ux_FIFO_EN (1<<0)#define Rx_FIFO_RST (1<<1)#define Tx_FIFO_RST (1<<2)#define DLAB_BIT (1<<7)#define LINE_FEED 0x0A //LF, For Linux, MAC and Windows Terminals #define CARRIAGE_RETURN 0x0D //CR, For Windows Terminals (CR+LF).
void initUART1(void);void U0Write(char data);
int main(void){ //SystemInit(); //This already gets called by CMSIS Startup Code. char msg[] = { 'H','e','l','l','o',' ','f','r','o','m',' ','L','P','C','1','7','6','8','\0' }; int count=0; initUART1(); while(1) { while( msg[count]!='\0' ) { U0Write(msg[count]); count++; } //Send NEW Line Character(s) i.e. "\n" U0Write(CARRIAGE_RETURN); //Comment this for Linux or MacOS U0Write(LINE_FEED); //Windows uses CR+LF for newline. count=0; // reset counter } //return 0; //This won't execute normally}
void U0Write(char txData){ while(!(LPC_UART1->LSR & THRE)); //wait until THR is empty //now we can write to Tx FIFO LPC_UART1->THR = txData;}
void initUART1(void){ /*Assuming CCLK = 100Mhz and PCLK = 25Mhz!*/ LPC_PINCON->PINSEL4 |= 0x0000000A; //Select TXD0 and RXD0 function for P0.2 & P0.3! //LPC_SC->PCONP |= 1<<3; //Power up UART0 block. By Default it is enabled after RESET.
LPC_UART1->LCR = 3 | DLAB_BIT ; /* 8 bits, no Parity, 1 Stop bit & DLAB set to 1 */ LPC_UART1->DLL = 12; LPC_UART1->DLM = 0; //LPC_UART0->IER |= ..; //Edit this if want you to use UART interrupts LPC_UART1->FCR |= Ux_FIFO_EN | Rx_FIFO_RST | Tx_FIFO_RST;// LPC_UART1>FDR = (MULVAL<<4) | DIVADDVAL; /* MULVAL=15(bits - 7:4) , DIVADDVAL=2(bits - 3:0) */ LPC_UART1->LCR &= ~(DLAB_BIT);} //Now since we have applied DLL and DLM we now lock or freeze those valuse by diabling DLAB i.e DLAB=0 //Baud= ~115200(114882). Now we can perform UART communication!