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

UART3 MCP2378

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.

Parents
  • 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.

Reply
  • 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.

Children