<span style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;">I have LPC800 mini board and able to blink led by example code.Now I want to make uart echo example but not able to receive data from terminal.I think I am missing some parameters setup to Receive data from terminal.</span><br style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;" /><br style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;" /><span style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;">please guide me or suggest some tutorial to set parameters or registers which are required to Receive data from terminal.</span><br style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;" /><br style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;" /><br style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;" /><span style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;">Regards,</span>
<span style="color: #555555; font-family: Arial, sans-serif; font-size: 11px; line-height: normal; background-color: #f2f7fb;">vs</span>
Hi Noah
You are right. I don't need to check TXRDY so only set a RXRDY interrupt.
You and mike help me a lot. Thank you for your support.
-----
vs
Hi mike
It's done. Actually before this help I set RXRDY and TXRDY (silly mistake), that's why didn't get any output.
Thank you very much for your support.
---
vs
Hi vs,
I hope Mike's help works for you on getting an ISR set up. I don't have much information on that. Regarding the ISR functionality you can do something like this:
main() {
INTENSET = (1 << 0); // enable rx rdy interrupt
};
isr() {
int intstat = INTSTAT;
if(intstat & (1 << 0)) { // rx rdy interrupt
TXDAT = RXDAT; // write rx data to tx buffer
}
}
For your situation, checking TXRDY doesn't seem necessary. You also don't want to enable the TXRDY interrupt, otherwise you will be stuck in the ISR. Another way of doing this with checking TXRDY could be: (Much more complicated than necessary for your situation, but useful for demonstrating functionality.)
int txrdy_flag;
main() {
txrdy_flag = 0;
INTENSET = (1 << 2) | (1 << 0); // enable tx and rx interrupts
}
isr() {
int intstat = INTSTAT; // equivalent to STAT & INTENSET: ie, only the statuses that you want interrupts for
if(intstat & (1 << 0)) { // rx rdy interrupt
if(!txrdy_flag)
abort_error();
txrdy_flag = 0;
TXDAT = RXDAT; // write rx data to tx buffer
INTENSET = (1 << 2); // re-enable tx rdy interrupt
}
if(intstat & (1 << 2)) { // tx rdy interrupt
if(txrdy_flag)
abort_error();
txrdy_flag = 1; // save tx rdy flag
INTENCLR = (1 << 2); // disable tx rdy interrupt
}
}
Noah
Hi mike
ok, I will try that .
vs
The IRQ handler declaration will look someting like this:
void UART0_IRQHandler(void) ALIAS(IntDefaultHandler);
where ALIAS is a MACRO:
#define ALIAS(f) __attribute__ ((weak, alias (#f)))
The 'weak' attribute means that this symbol may be over-written by a 'strong' symbol with the same name.
So if you name your interrupt handler '<span class="nf">UART0_IRQHandler()' the toolchain will take care of linking your interrupt handler to the vector table.
</span>
Apart from that, the only other thing you should need to do is set the RX_RDY bit in the USART INTENSET register.
--
mike
Hi Noah
I tried that it is working.
Now I want to receive data by interrupt method. Please help me.
Thank you Noah
vs
Hi mike
I am using gcc compiler and LPCxpresso IDE. I configured NVIC to enable UART0_IRQn and also set priority"NVIC_SetPriority(UART0_IRQn,1)"and linked interrupt handler to vector table but still not getting interrupt on RX.
In declaration of specific IRQ handlers(lpc8xx startup C file), all IRQ handlers(uart0, uart1, uart2,..etc) are alised to the Intdefaulthandler, which is a 'forever' loop. Should I have to change in that declaration?
Hi vs,
I just looked at the code I wrote again, and it was wrong, here's a single line that should work better:
while(~STAT & ((1 << 0) | (1 << 2)));
The way it was written first would continue if tx OR rx was ready. I meant to have it wait for both.
Noah
Hi vs
Should be no need for a pragma, the cortex was designed to be able to call a 'C' function directly from an interrupt. Although this may depend on the compiler you are using...
You should just have to link your interrupt handler to the vector table.
How this is done depends on the compiler and the way the envirionment has been set-up but you should be able to find a vector table somewhere.
You will also need to configure the NVIC to enable the irq and set its priority.
--
mike
Hi mike
my program is working with these parameters configuration with polling method now want to receive by interrupt subroutine.
one question : for interrupt subroutine, is it require pragma?
Thanks
vs
Thanks for the help. your code is working but with little modification.
CFG = (1 << 2) | (1 << 0); // set datalen to 8 and turn on uart
while(1) {
<strong>while(!(STAT & ((1 << 0)))); // wait for rx data</strong>
TXDAT = RXDAT;
Regard,
vs
Here's a few things you'll need to set-up to get a USART working, using USART0 as an example on the ISP TX/RX pins.
1. Enable the pins in the Switch Matrix
/* UART0: TXD = P0.4, RXD = P0.0) */
LPC_SWM->PINASSIGN0 = ((0xFFFF0000) | (0<<8) | (4));
2. Configure the Fractional baud rate generator (not always required).
I configure it to give a U_PCLK of 11.0592MHz from the 12MHz OSC. That will divide nicely into any standard baud rate.
/* Configure fractional baudrate generator */
LPC_SYSCON->PRESETCTRL &= ~(1<<2);
LPC_SYSCON->PRESETCTRL |= (1<<2);
LPC_SYSCON->UARTCLKDIV = LPC8xx_SERIAL_UARTCLKDIV;
LPC_SYSCON->UARTFRGDIV = LPC8xx_SERIAL_UARTFRGDIV;
LPC_SYSCON->UARTFRGMULT = LPC8xx_SERIAL_UARTFRGMULT;
3. Enable the peripheral clock
/* Enable Clk */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<14);
4. Configure the USART
/* Configure USART0 */
LPC_SYSCON->PRESETCTRL &=~(1<3);
LPC_SYSCON->PRESETCTRL |=(1<3);
LPC_USART0->BRG = (LPC8xx_SERIAL_U_PCLK / ( speed<<4 )) -1;
LPC_USART0->CFG = CFG_DL8 | CFG_NOPARITY | CFG_STOP1 | CFG_ENA;
That should be enough to get you going. I've left some of the detail, like the Fractional baud rate generator setup, for you to work out....
--
mike
Hi vs,
Here's an off-the-cuff simple example of a loopback for 8 bit, no parity, 1 stop bit:
CFG = (1 << 2) | (1 << 0); // set datalen to 8 and turn on uart
while(1) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>while(~STAT & ((1 << 0) | (1 << 2))); // wait for tx rdy and rx rdy
<span class="Apple-tab-span" style="white-space: pre;"> </span>TXDAT = RXDAT;
}
Hope this helps,
Noah