Hello, I'm trying to get my 1788's uart (uart3) working. I have initialized the uart correctly (or so I think). cclk = 12MHz pclk = cclk / 4
snippet of my uart setup code:
LPC_SC->PCONP |= (0x01 << 25); // Enable PCUART3 LPC_IOCON->P0_0 = 0x02; // 0b00010 => Setup as UART3 TXD, no pulldown or pull up. LPC_IOCON->P0_1 = 0x02; // 0b00010 => Setup as UART3 RXD, no pulldown or pull up. // Set DLAB=1 so we can set the baud rates for uart 3. LPC_UART3->LCR = (0x01 << 7); // input clk = 120MHz // pclk = in_clk / 2 = 60MHz // Baud = 31250 bits per sec // Divider = (pclk / (16.0 * baud)) // = 120 = 0x0078 LPC_UART3->DLM = 0x00; // MSB = 0x00 LPC_UART3->DLL = 0x06; // LSB = 0x78; LPC_UART3->FDR = 0x10; // diavdd = 0, mulval = 1 // Set up Rx and Tx FIFO. LPC_UART3->FCR = 0x07 ; // 0b0000_0111 // Set DLAB=0 since we plan on using interrupts. // Set UART3 for 8 bit data, 1 stop bit, no parity bit. LPC_UART3->LCR = 0x03; // Interrupt handler. NVIC_EnableIRQ(UART3_IRQn); // Disable Transmit. LPC_UART3->TER = 0x0; // Interrupt setup. LPC_UART3->IER = 0x01; // 0b0001 Onl
My interrupt handler does:
const uint32_t iir = LPC_UART3->IIR; const uint32_t type = (iir & 0x0f) >> 1; if (iir & 0x01) { return; // We apparently have nothing here. } if (type == IIR_RDA) { const uint32_t lsr = LPC_UART3->LSR; // *** Often indicates a framing error ?!?! // Read data availabe. { const uint8_t ch = (LPC_UART3->RBR & 0xFF); HandleRead(ch); } } else if (type == IIR_RLS) { ... }
I'm testing my code by using a standard message generator which sends messages that I can control. The bytes that I receive in the interrupt handler seem firstly _bad_ (or wrong) and I see a framing error. I've checked and double checked the baud/clks/dividers/parity/stop bits etc. I can't see what I'm doing wrong. Perhaps someone here can point out what I'm missing ...
Been stuck on this for a while now :(
Thanks.
Well I don't have a reasonable scope - that is a situation that is remedied easily enough. I guess a decent scope is a must for such work.