Good Afternoon to all, I'm working with ARM processor LPC1768 in a MCB1700 board, and in my project i need to use uart to communicate with a PLC modem. I'm using the code bellow to do this. If a try to communicate with a Hyperterminal or similar on windows, my interruption works fine, but if a try to communicate with the before mentioned PLC modem, a can't get any interrupts. I have probed the uart pins P2.0 and P2.1 and the PLC modem pins, and i can see that my TX messages arrive on the modem, and i can see that the modem answer those messages accordingly, and i can see that the uart RX pin receives those messages, but no interruption are toggled...
Can anyone help me with this issue? any suggestion to other uart implementation?
//--------------------------------------------------------------------------- #include <LPC17xx.h> #include "Serial.h" //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Defines //--------------------------------------------------------------------------- #define SW_FIFO_SIZE 512 #define RLS_INTERRUPT 0x03 #define RDA_INTERRUPT 0x02 #define CTI_INTERRUPT 0x06 #define THRE_INTERRUPT 0x01 #define LSR_RDR (1<<0) #define LSR_OE (1<<1) #define LSR_PE (1<<2) #define LSR_FE (1<<3) #define LSR_BI (1<<4) #define LSR_THRE (1<<5) #define LSR_TEMT (1<<6) #define LSR_RXFE (1<<7) #define UART_DISABLED 0x00 #define UART_OPERATIONAL 0x01 #define UART_OVERFLOW 0x02 #define UART_PARITY_ERROR 0x03 #define UART_FRAMING_ERROR 0x04 #define UART_BREAK_DETECTED 0x05 #define UART_CHAR_TIMEOUT 0x06 //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- BYTE UART0_RxBuf[UART0_RX_BUFFER_SIZE]; BYTE UART0_TxBuf[UART0_RX_BUFFER_SIZE]; BYTE UART0_RxTail; BYTE UART0_RxHead; BYTE uart0_tx_sts; BYTE uart0_rx_sts; uint32_t rdaInterrupts = 0; uint32_t ctiInterrupts = 0; //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // Controle //--------------------------------------------------------------------------- void Serial0Init( unsigned int baudRate ) { int pclk, fdiv; LPC_SC->PCONP |= (1 << 3); LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ LPC_SC->PCLKSEL0 &= ~(3 << 6); // clear bits LPC_SC->PCLKSEL0 |= (1 << 6); // set to "01" (full speed) pclk = SystemCoreClock; LPC_UART0->LCR = 0x03; /* 8 bits, no Parity, 1 Stop bit */ LPC_UART0->LCR |= (1 << 7); /* fdiv = (pclk/(16*baudRate)); LPC_UART0->DLM = (fdiv >> 8) & 0xFF; LPC_UART0->DLL = (fdiv) & 0xFF; */ // baudrate of 38400 with a clock rate of 100 MHz LPC_UART0->DLM = 0;//Fdiv / 256; LPC_UART0->DLL = 108;//Fdiv % 256; LPC_UART0->FDR = 0x21;/// LPC_UART0->LCR &= ~(1 << 7); LPC_UART0->FCR |= (0x0 << 6); //(0x3 = 14, 0x00 = 1) //LPC_UART0->FCR |= 0x01; //LPC_UART0->FCR |= 0x06; NVIC_EnableIRQ(UART0_IRQn); NVIC_SetPriority(UART0_IRQn,30); LPC_UART0->IER = 0x07; //Enable LPC_UART0->LCR = 0x03; } //--------------------------------------------------------------------------- void UART0_IRQHandler(void) __irq { BYTE intId, lsrReg; BYTE byData,bTmpTail; intId = ((LPC_UART0->IIR)>>1)& 0x7; if(intId == RLS_INTERRUPT) { //RLS lsrReg = LPC_UART0->LSR; if (lsrReg & LSR_OE) uart0_rx_sts = UART_OVERFLOW; else if (lsrReg & LSR_PE) uart0_rx_sts = UART_PARITY_ERROR; else if (lsrReg & LSR_FE) uart0_rx_sts = UART_FRAMING_ERROR; else if (lsrReg & LSR_BI) uart0_rx_sts = UART_BREAK_DETECTED; } else if (intId == RDA_INTERRUPT) { while((LPC_UART0->LSR) & 0x1) { UART0_RxBuf[UART0_RxHead] = LPC_UART0->RBR; UART0_RxHead += 1; if (UART0_RxHead == UART0_RX_BUFFER_SIZE) UART0_RxHead = 0; } rdaInterrupts++; } else if (intId == CTI_INTERRUPT) { while((LPC_UART0->LSR) & 0x1) { UART0_RxBuf[UART0_RxHead] = LPC_UART0->RBR; UART0_RxHead += 1; if (UART0_RxHead == UART0_RX_BUFFER_SIZE) UART0_RxHead = 0; } ctiInterrupts++; } } //---------------------------------------------------------------------------