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.
hi all , I am trying to configure the UART 3 of MCP2378 for the baud rate 115200.i successfully configured UART0 for the same baud rate .but when i tried it with UART 3 i get some junk values probably due to some baud rate miss match following is the code used for initialization.
void UARTInit(u8 ucPortNo,u16 ucBaudrate) { UART_BaudRateConfig(ucPortNo,ucBaudrate);
switch(ucPortNo) {
case 0: PINSEL0 =0x00000050; U0FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break;
case 1: PINSEL0 |=0x40000000; //original PIN configuration PINSEL1 |=0x00000001; U1FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break;
case 2: PCONP |=0x01000000; PINSEL0 |=0x00500000;//selecting thefunction for the pins
// PINSEL4 |= 0x000A0000; U2FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break;
case 3: PCONP |=0x02000000; PINSEL9 |=0x0f000000;//selecting the function for the pin // PINSEL1 |= 0x003E0000; U3FCR =0x07; /* Enable and reset TX and RX FIFO.*/
break; } }
UART_BaudRateConfig(u8 PortNo,u16 Baudrate) { u16 DIV; switch(PortNo) { case 0: U0LCR =0x83; // DIV=((Fpclk/16)/Baudrate); // U0DLM = (DIV/256); // U0DLL = (DIV%256); U0DLM =0x0; U0DLL =8;//0xa+;75 /* 38793 =0x1d */ U0FDR=0x92; U0LCR=0x03; break;
case 1:U1LCR =0x83; // DIV=((Fpclk/16)/Baudrate); U1DLM =DIV / 256; U1DLL =DIV % 256; U1LCR=0x03; break;
case 2:U2LCR =0x83; U2TER =0x80; // DIV=((Fpclk/16)/Baudrate); // U2DLM =DIV / 256; // U2DLL =DIV % 256; U2DLM =0x0; U2DLL =8; U2FDR=0x92; U2LCR =0x03; break;
case 3:U3LCR =0x83;
// DIV=((Fpclk/16)/Baudrate); // U3DLM =DIV / 256; // U3DLL =DIV % 256; U3DLM =0x0; U3DLL =8;//0xa+;75 /* 38793 =0x1d */ U3FDR=0x92; U3LCR=0x03; U3TER =0x80; break; } }
here I directly configured the UART for 115200.I am using 24mhz main clock.
hi Per Westermark, PCLK for both UART is same,CCLK/4. Here i am reposting the code please help .
int main (void) { u8 ch1; UARTInit(3,112500); while(1) { ch1=UARTByteRead(3); UARTByteSend(3,ch1); } while(1); } u8 UARTByteRead(u8 ucPortNo) { u8 ch; switch(ucPortNo) { case 0: while(!(U0LSR & LSR_RDR)); ch=U0RBR; break; case 1: while(!(U1LSR & LSR_RDR)); ch=U1RBR; break; case 2: while(!(U2LSR & LSR_RDR)); ch=U2RBR; break; case 3: while(!(U3LSR & LSR_RDR)); ch=U3RBR; break; } return(ch); } u8 UARTByteSend(u8 ucPortNo,u8 ucByte) { switch(ucPortNo) { case 0: U0THR =ucByte; while(!(U0LSR & LSR_TEMT )); break; case 1:U1THR =ucByte; while (!(U1LSR & LSR_TEMT )); break; case 2: U2THR = ucByte; while (!(U2LSR & LSR_TEMT)); break; case 3: U3THR = ucByte; while (!(U3LSR & LSR_TEMT)); break; } } void UARTInit(u8 ucPortNo,u16 ucBaudrate) { UART_BaudRateConfig(ucPortNo,ucBaudrate); switch(ucPortNo) { case 0: PINSEL0 =0x00000050; U0FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break; case 1: PINSEL0 |=0x40000000; //original PIN configuration PINSEL1 |=0x00000001; U1FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break; case 2: PCONP |=0x01000000; PINSEL0 |=0x00500000;//selecting thefunction for the pins U2FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break; case 3: PCONP |=0x02000000; // enabling the clock for uart3 PINSEL9 |=0x0f000000;//selecting the function for the pins p4.28 & p4.29 U3FCR =0x07; /* Enable and reset TX and RX FIFO.*/ break; } } UART_BaudRateConfig(u8 PortNo,u16 Baudrate) { u16 DIV; switch(PortNo) { case 0: U0DLM =0x0; U0DLL =8; U0FDR=0x92; U0LCR=0x03; break; case 1:U1LCR =0x83; U1DLM =DIV / 256; U1DLL =DIV % 256; U1LCR=0x03; break; case 2:U2LCR =0x83; U2TER =0x80; U2DLM =0x0; U2DLL =8; U2FDR=0x92; U2LCR =0x03; break; case 3:U3LCR =0x83; U3DLM =0x0; U3DLL =8; U3FDR=0x92; U3LCR=0x03; U3TER =0x80 break; } }
.
First of all, you have an interested "spelling" of 115200 baud:
UARTInit(3,112500);
Secondly - you send an actual baudrate, but your baudrate-setting code doesn't even look at a baudrate parameter. For UART1, you use an uninitialized variable DIV, and for UART0, UART2 and UART3 you use a hard-coded baudrate divisor.
hi, It was intended to be a generalized code but when uart 3 din work I hard coded the value for it.please tell me whether the steps used to configure uart is right or wrong.Is there any new modifications required to configure the same?
You have this line:
PCONP |=0x02000000; // enabling the clock for uart3
First of all - the comment is wrong. PCONP turns on power for peripherials. It doesn't have anything with the clock to do.
Second, the UART3 device is bit 29 so you should do:
PCONP |= 1u << 29;
Your code has one zero too little, and corresponds to bit 25, so you are turning on power to DMA. This should be visible if you use the IDE and look at all settings in the Peripherials menu.
It always helps to use explicitly named constants and have impeccable comments.
Sorry, I mixed up the # of digits :(
hi, For LPC 2378 UART 3 power on bit corresponds to position 25 of PCONP.
hi all, If any body have configured UART3 or UART2 please help me. An early reply is highly awaited .