Steps for setting an UART interrupt

cancel
Showing results for 
Search instead for 
Did you mean: 

Steps for setting an UART interrupt

1,715 Views
NXP Employee
NXP Employee
Content originally posted in LPCWare by Lazar92 on Tue Apr 21 02:34:46 MST 2015
Steps that I went through during setup of UART interrupt are:
1) Initialize UART2 peripheral and required pins
2) Clear DLAB bit in LCR register
3) Enable RBRIE and THREIE interrupt bits (flag bits) in IER register
4) Enable interrupt for UART2 with NVIC_EnableIRQ(UART2_IRQn)
5) Masked 2 bits RDR and THRE in IIR register and checking them all the time if they are set, if RDA is set go to receive function, if THRE is set go to send function and thats it. Are there steps that I forgot and that may be the reason it wont work?

Is there something in code I forgot, bcs when i follow this steps interrupt won't work?

#define   SMR_485TRANSMIT LPC_GPIO5->SET |=  (1<<0)  //CHANGE DATA FLOW TO TRANSMIT
#define   SMR_485RECEIVE  LPC_GPIO5->CLR |=  (1<<0)  //CHANGE DATA FLOW TO RECEIVE

int main(void) {

uart2();
NVIC_EnableIRQ(UART2_IRQn);
while(1) {
}
}

void receive(void) {

SMR_485RECEIVE;
delay_10_micro();
        receive_byte = LPC_UART2->RBR;

    }

void send(void) {

SMR_485TRANSMIT; 
delay_1_ms();
        LPC_UART2->THR = receive_byte;
    }

void UART2_IRQHandler(void) {

BYTE maska = LPC_UART2->IIR & 0x04;

        if(maska == 0x04){
             receive();
     delay_10_micro();
             send();
     delay_10_micro();
             } 
}


void uart2(void){

LPC_SC->PCONP |= (1<<24);  // power to the uart2 peripheral 

LPC_UART2->LCR = 0x83; // 8 bits, parity none, stopbit 1, DLAB ENABLED

LPC_UART2->FCR = 7; // FIFO enable, Rx FIFO reset, Tx FIFO reset
LPC_UART2->FCR = 1; // reset fifo

/* Then reset DLAB bit */
LPC_UART2->LCR = 0x03; // disable DLAB so that interrupts are enabled

LPC_UART2->IER = 0x03; 

        //pinsel for UART2
 LPC_IOCON->P0_10 = 1; // UART2 TXD
 LPC_IOCON->P0_11 = 1; // UART2 RXD
 LPC_IOCON->P5_0 =  0; // SMR_485 

 LPC_GPIO5->DIR |= (1<<0);

}

Labels (1)
0 Kudos
1 Reply

177 Views
NXP Employee
NXP Employee
Content originally posted in LPCWare by nerd herd on Wed Apr 22 07:48:08 MST 2015
Hi Lazar92,

Have you checked our LPCOpen software platform for a UART example?

http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc17xx-packages
0 Kudos