LPC810 uart_echo help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC810 uart_echo help

978 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Fri Jun 14 05:22:22 MST 2013

<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>

Labels (1)
0 Kudos
13 Replies

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Wed Jun 19 23:25:14 MST 2013

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

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Wed Jun 19 23:19:25 MST 2013

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

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by noahk on Tue Jun 18 12:25:20 MST 2013

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 &lt;&lt; 0); // enable rx rdy interrupt
}; 


isr() {
  int intstat = INTSTAT;
  if(intstat &amp; (1 &lt;&lt; 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 &lt;&lt; 2) | (1 &lt;&lt; 0); // enable tx and rx interrupts
}


isr() {
  int intstat = INTSTAT; // equivalent to STAT &amp; INTENSET: ie, only the statuses that you want interrupts for
  if(intstat &amp; (1 &lt;&lt; 0)) { // rx rdy interrupt
    if(!txrdy_flag)
      abort_error();
    txrdy_flag = 0;
    TXDAT = RXDAT; // write rx data to tx buffer
    INTENSET = (1 &lt;&lt; 2); // re-enable tx rdy interrupt
  }
  if(intstat &amp; (1 &lt;&lt; 2)) { // tx rdy interrupt
    if(txrdy_flag)
      abort_error();
    txrdy_flag = 1; // save tx rdy flag
    INTENCLR = (1 &lt;&lt; 2); // disable tx rdy interrupt
  }
}


Noah

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Tue Jun 18 07:32:27 MST 2013

Hi mike


ok, I will try that .

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheShed on Tue Jun 18 05:29:20 MST 2013

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

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Tue Jun 18 03:50:52 MST 2013

Hi Noah


I tried that it is working.


Now I want to receive data by interrupt method. Please help me.


 


Thank you Noah


vs

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Tue Jun 18 03:36:01 MST 2013

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?


<div>----</div>
<div>vs</div>
0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by noahk on Sun Jun 16 10:28:18 MST 2013

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 &amp; ((1 &lt;&lt; 0) | (1 &lt;&lt; 2)));


The way it was written first would continue if tx OR rx was ready. I meant to have it wait for both.


Noah

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheShed on Sun Jun 16 03:40:45 MST 2013

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

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Sat Jun 15 22:36:37 MST 2013

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

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vs on Sat Jun 15 22:04:18 MST 2013
<h3>Hi noah,</h3>

Thanks for the help. your code is working but with little modification.


CFG = (1 &lt;&lt; 2) | (1 &lt;&lt; 0); // set datalen to 8 and turn on uart
while(1) {
<strong>while(!(STAT &amp; ((1 &lt;&lt; 0)))); // wait for rx data</strong>
TXDAT = RXDAT; 


Regard,


vs 

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheShed on Sat Jun 15 02:09:40 MST 2013


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-&gt;PINASSIGN0 = ((0xFFFF0000) | (0&lt;&lt;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-&gt;PRESETCTRL &amp;= ~(1&lt;&lt;2);
LPC_SYSCON-&gt;PRESETCTRL |= (1&lt;&lt;2);
LPC_SYSCON-&gt;UARTCLKDIV = LPC8xx_SERIAL_UARTCLKDIV;
LPC_SYSCON-&gt;UARTFRGDIV = LPC8xx_SERIAL_UARTFRGDIV;
LPC_SYSCON-&gt;UARTFRGMULT = LPC8xx_SERIAL_UARTFRGMULT;


3. Enable the peripheral clock
/* Enable Clk */
LPC_SYSCON-&gt;SYSAHBCLKCTRL |= (1&lt;&lt;14);


4. Configure the USART
/* Configure USART0 */
LPC_SYSCON-&gt;PRESETCTRL &amp;=~(1&lt;3);
LPC_SYSCON-&gt;PRESETCTRL |=(1&lt;3);
LPC_USART0-&gt;BRG = (LPC8xx_SERIAL_U_PCLK / ( speed&lt;&lt;4 )) -1;
LPC_USART0-&gt;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

0 Kudos

885 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by noahk on Fri Jun 14 17:59:00 MST 2013

Hi vs,


Here's an off-the-cuff simple example of a loopback for 8 bit, no parity, 1 stop bit:


CFG = (1 &lt;&lt; 2) | (1 &lt;&lt; 0); // set datalen to 8 and turn on uart
while(1) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>while(~STAT &amp; ((1 &lt;&lt; 0) | (1 &lt;&lt; 2))); // wait for tx rdy and rx rdy
<span class="Apple-tab-span" style="white-space: pre;"> </span>TXDAT = RXDAT;
}


Hope this helps,
Noah

0 Kudos