Hi,
I am using "LPCXpresso 4367 Development board" for LPC4367 series evaluation. I want to know the configuration process or flow of UART driver API's since i was facing some issues in configuration of stop and parity bits.
I have attached the driver file for reference. When i call setParityBit(ui_ParityBitSetting); and
setStopBits(ui_StopBitSetting); functions i get a hardfault interrupt.
Kindly help in resolving this issue.
Tx Port: P2_10_U2_Tx (E8)
Rx Port: P2_11_U2_Rx(A9)
The code works fine when i comment setParityBit(ui_ParityBitSetting); and
setStopBits(ui_StopBitSetting); functions.
Thanks and best regards,
Prasanna
Hi Prasanna Naik,
Let's analysis the API Chip_UART_ConfigData function at first:
From the user manual, we can know the details about the LCR register:
So, please check your setParityBit and setStopBits, just take this PARTITY_EVEN as an example, you write it like this:
Please consider it, if you call this code after you have called the Chip_UART_Init:
/* Initializes the pUART peripheral */
void Chip_UART_Init(LPC_USART_T *pUART)
{
volatile uint32_t tmp;
/* Enable UART clocking. UART base clock(s) must already be enabled */
Chip_Clock_EnableOpts(UART_PClock[Chip_UART_GetIndex(pUART)], true, true, 1);
/* Enable FIFOs by default, reset them */
Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS));
/* Disable Tx */
Chip_UART_TXDisable(pUART);
/* Disable interrupts */
pUART->IER = 0;
/* Set LCR to default state */
pUART->LCR = 0;
/* Set ACR to default state */
pUART->ACR = 0;
/* Set RS485 control to default state */
pUART->RS485CTRL = 0;
/* Set RS485 delay timer to default state */
pUART->RS485DLY = 0;
/* Set RS485 addr match to default state */
pUART->RS485ADRMATCH = 0;
/* Clear MCR */
if (pUART == LPC_UART1) {
/* Set Modem Control to default state */
pUART->MCR = 0;
/*Dummy Reading to Clear Status */
tmp = pUART->MSR;
}
/* Default 8N1, with DLAB disabled */
Chip_UART_ConfigData(pUART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS));
/* Disable fractional divider */
pUART->FDR = 0x10;
}
What will happen?
You will just set UART_LCR_PARITY_EN and UART_LCR_PARITY_EVEN, the WLS will be retrun back to 0X0, it is 5 bit character length, and others all will be back to 0.
So, I think if you want to configure the according bit, you can configure the LCR directly, just clear that according bit, and set it again, don't influence the other LCR bits.
Take example, after you called Chip_UART_Init function, then you want to set the Parity and Even, then you call this code:
LPC_UART->LCR &= ~(UART_LCR_PARITY_EN |UART_LCR_PARITY_F_0); // clean according bits
LPC_UART->LCR |= (UART_LCR_PARITY_EN | UART_LCR_PARITY_EVEN);// enable parity and conifigure Even Parity.
The stop is the same, when you want to configure the SBS, you can clear LCR register bit 2 at first, then use "|" to configure it.
Just make sure you won't influence other bits in the LCR.
About the flow, you can configure it after Chip_UART_Init function.
Wish it helps you!
Please try it on your side.
If you still have question about it, please kindly let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------