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

I can't find out why my TxD1 does not transmit.

I have a problem with the UART1 port (on P0.1 and P0.16). It sends no data.
My initialisation:
void Seriel_init (void)
{ // TxD: Port 0.17
// RxD: Port 0.16
LPC_PINCON->PINSEL0 |= 0x40000000; // set bit
LPC_PINCON->PINSEL1 |= 0x00000001; // set bits
LPC_PINCON->PINMODE0 |= 0x80000000; //set bit
LPC_PINCON->PINMODE1 |= 0x00000002; // set
// complex initialisation routine
LPC_SC->PCONP |= 0x00000010; // Set bit
LPC_SC->PCLKSEL0 |= 0x00000100; // Set bit
LPC_UART1->LCR |= 0x83; // set bit s

// Baudrate: 19.200 Baud per secondds
LPC_UART1->DLM = 0; // set to 0
LPC_UART1->DLL = 52; // set to 50?
LPC_UART1->LCR |= 0x03; // set 2 bits
LPC_UART1->FDR = 0x01; // set to 1
LPC_UART1->FCR |= 0x07; // set 4 bits
LPC_UART1->TER |= 0x80; // set bit
LPC_UART1->IER |= 0x02; // set 5 bits
}

For sending a character, I use the following code:

unsigned char UART1_PutChar (unsigned char ch)
{ while (!(LPC_UART1->LSR & 0x20)); // is bit set
return (LPC_UART1->THR = ch); // put ch into reg
}

Nothing happens on TxD1 .
tell me why.

Parents
  • People always uses so interesting comments:

    LPC_UART1->DLM = 0; // set to 0 <=== set _what_ to zero?
    LPC_UART1->DLL = 52; // set to 50? How did you compute your 50 or 52? Why hardcoded value?
    LPC_UART1->LCR |= 0x03; // set 2 bits <=== what did you set to 2 bits?
    LPC_UART1->FDR = 0x01; // set to 1 <=== set what to 1? Why?
    LPC_UART1->FCR |= 0x07; // set 4 bits
    LPC_UART1->TER |= 0x80; // set bit <=== you mean this helps someone? "set bit"???
    LPC_UART1->IER |= 0x02; // set 5 bits <=== You set "5 bits"?
    

    Are these comments really the best you can come up with? Exactly what do you think the comments does? Help you? Help someone else? Do they really add anything? Do they remove the need to read the datasheet?

    Another thing - try to avoid magic numbers. If you give these numbers some names - in form of enum or #define - then it will suddenly be possible to read the source code line (excluding any comment) and see what you are assigning to the register.

    If you can't write readable code, then you will get stuck. You will wonder why nothing works. And you will not be able to look at the code and figure where something may be wrong. It will take just as much time - again - to try to compare everything with the datasheet. And next time you revisit the code, it will be the same again. And again. And again.

    Try to make the assign have meaningful names so you know _what_ it does. Then - if needed - add comments that tells the reader _why_ you do it.

Reply
  • People always uses so interesting comments:

    LPC_UART1->DLM = 0; // set to 0 <=== set _what_ to zero?
    LPC_UART1->DLL = 52; // set to 50? How did you compute your 50 or 52? Why hardcoded value?
    LPC_UART1->LCR |= 0x03; // set 2 bits <=== what did you set to 2 bits?
    LPC_UART1->FDR = 0x01; // set to 1 <=== set what to 1? Why?
    LPC_UART1->FCR |= 0x07; // set 4 bits
    LPC_UART1->TER |= 0x80; // set bit <=== you mean this helps someone? "set bit"???
    LPC_UART1->IER |= 0x02; // set 5 bits <=== You set "5 bits"?
    

    Are these comments really the best you can come up with? Exactly what do you think the comments does? Help you? Help someone else? Do they really add anything? Do they remove the need to read the datasheet?

    Another thing - try to avoid magic numbers. If you give these numbers some names - in form of enum or #define - then it will suddenly be possible to read the source code line (excluding any comment) and see what you are assigning to the register.

    If you can't write readable code, then you will get stuck. You will wonder why nothing works. And you will not be able to look at the code and figure where something may be wrong. It will take just as much time - again - to try to compare everything with the datasheet. And next time you revisit the code, it will be the same again. And again. And again.

    Try to make the assign have meaningful names so you know _what_ it does. Then - if needed - add comments that tells the reader _why_ you do it.

Children
No data