Hi
Not able to Read U0RBR in UART0 interrupt(for receive - RDA interrupt ). My UART0 interrupt is working (i have put the Break point) but the U0RBR register showing always Zero value. In polling method i am able read the values from U0RBR register so no issues in communication. UART0 initialization code and UART0 Interrupt code mentioned below. Please help me regarding the same.
thanks Goran
/*============================================================================ Function: Serial_UART3_Init(void) ============================================================================= Function description : Intilizes UART 3 Prototype : void Serial_UART3_Init(void) Parameter : None Return : None Baud rate calculation : PCLK UART3 Baudrate = ---------------------------------------------------------- (16 x ((256 x U3DLM)+ U3DLL) x (1 + (DivAddVa / MulVal)) pclk = 12MHz U3DLM = 0 U3DLL = 71; DivAddVa = 1 MulVal = 10 UART3 Baudrate = 9603 ; which is near to 9600 Baud rate. This gives U3DLL = 71 U3FDR = 0xA1 */ void Serial_UART0_Init(void) { PINSEL0=0x00000050; // Configure P0.2 as TXD0 and P0.3 as RXD0; pull-up resistor enabled U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit ,Enable access to Divisor Latches. U0DLL = 71; // 9603 Baud Rate @ 12MHz PCLK Clock U0FDR = 0xA1; // Fractional Divider U0LCR = 0x03; // DLAB = 0 U0IER = 0x01; // Enable RDA interrupt } /*============================================================================ ============================================================================*/ /*============================================================================ Function: Interrupt_Init(void) =============================================================================*/ void Interrupt_Init(void) { VICVectAddr4 = (unsigned long) TIMER0_IRQHandler; /* set interrupt vector 4 */ VICVectPriority4 = 15 ; /* default priority is 15 */ VICIntEnable |= ((unsigned long)1<<4); /* Enable TIMER0 Interrupt */ VICVectAddr6 = (unsigned long) UART0_IRQHandler; /* set interrupt vector 6 */ VICVectPriority6 = 15 ; /* default priority is 15 */ VICIntEnable |= ((unsigned long)1<<6); /* Enable UART0 Interrupt */ } /*============================================================================ ============================================================================*/ /*===========================================================================* *ISR: UART0 :serial receive and transmit interrupt * *===========================================================================*/ __irq void UART0_IRQHandler(void) { RX_BUF[rx_count] = (char)U0RBR; if ((U0IIR & 0x0E) == 0x04) { if(rx_count == 0) { RX_BUF[rx_count] = (char)U0RBR; if(RX_BUF[0]== Slave_Address) { rx_count++; } else rx_count = 0; } else { RX_BUF[rx_count++] = U0RBR; } if(rx_count >= 8) { rx_count = 0; if( (RX_BUF[0]== Slave_Address) && ((RX_BUF[1]==Function_Code)||(RX_BUF[2]==AddressFunCode_LOWBYTE))) rx_flag = 1; } } /* Receive Mode end */ uart0_flag = 1; VICVectAddr = 0; /* Acknowledge Interrupt */ }
Why do you do an obligatory read from U0RBR directly you enter the ISR?
Always poll U0IIR and decide what to do based on that result. Never read registers that are "read-once" unless you know that they have data available.
And why are you so scared of adding comments?
I see "if ((U0IIR & 0x0E) == 0x04)" but how do I know that 0x04 represents "Receive Data Available" if I haven't the processor documentation available?
Next thing - when you get into the ISR, there may be more than one pending interrupt reason. You don't seem to care about bit 0 of U0IIR to see if there are more to do.
And why do you reset a variable that is already zero in case it wasn't your address?
Have you really been careful in reading the processor manual? And in debugging your code?