0

I am trying to send a byte using UART1 in LPC1778 (I'm Using Keil Simulator).

However I'm not able to send the byte; after detailed debugging, I came to the conclusion that data is not getting written in the UART1->THR register.

This is the code snipped for transmission:

void uart1_tra(uint8_t x)
{
    LPC_UART1->THR=x;
    //after this line ,irrespective of the value of x, UART1->THR remains at a 
    VALUE EQUAL TO 0         

    while(1)
    {
        if(LPC_UART1->LSR&(1<<5))
        {
            break;
        }
    }
}

Initialization code:

void uar1_init(void) 
{
    LPC_SC->PCONP|=1u<<4; 
    LPC_SC->PCLKSEL|=1U; 
    LPC_UART1->LCR|=1U<<7; 
    LPC_UART1->DLL|=0x05; //SET SOME BAUD RATE 
    LPC_UART1->FDR|= 0x21; //END OF BAUD RATE CALCULATIONS
    LPC_UART1->LCR&=~(1U<<7);//DISABLE DLAB 
    LPC_UART1->LCR|=3U;//8-BITCHARACTER LENGTH 
    LPC_UART1->FCR|=1U; //ENABLE FIFO REG 
    LPC_UART1->FCR|=(0X03<<1);//RESET RXBUFFERS 
    //LPC_UART1->IER|=3u;//to ENABLE INTERRUPTS 
    LPC_IOCON->P0_15|=1U; 
    LPC_IOCON->P0_16|=1; 
}
Alexey Esaulenko
  • 499
  • 2
  • 10
  • you have properly initialized the uart before getting to this point? does the scope show the character going out of the chip? – old_timer Jul 05 '16 at 15:37
  • Yes i have , i will atatch the code below ,please have a look. – Debayan Ghosh Jul 08 '16 at 08:20
  • Yes i have , i will attatch the code below ,please have a look.void uar1_init(void) { LPC_SC->PCONP|=1u<<4; LPC_SC->PCLKSEL|=1U; LPC_UART1->LCR|=1U<<7; LPC_UART1->DLL|=0x05; //SET SOME BAUD RATE LPC_UART1->FDR|= 0x21; //END OF BAUD RATE CALCULATIONS LPC_UART1->LCR&=~(1U<<7);//DISABLE DLAB LPC_UART1->LCR|=3U;//8-BITCHARACTER LENGTH LPC_UART1->FCR|=1U; //ENABLE FIFO REG LPC_UART1->FCR|=(0X03<<1);//RESET RXBUFFERS //LPC_UART1->IER|=3u;//to ENABLE INTERRUPTS LPC_IOCON->P0_15|=1U; LPC_IOCON->P0_16|=1; } – Debayan Ghosh Jul 08 '16 at 08:27
  • First, THR register is write only (see user manual for your MCU). Second, try to run this code in real hardware. Unfortunately, simulator has numerous errors... – Alexey Esaulenko Jul 08 '16 at 09:43
  • Thanks a lot Alexey, tried the same code in the hardware, it is sending and receiving data. – Debayan Ghosh Jul 11 '16 at 07:28

0 Answers0