Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

NEED help in building a function with UART RX

Status
Not open for further replies.

arunkollam

Junior Member level 2
Junior Member level 2
Joined
Jun 26, 2008
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,412
Can any one have an idea in building a function which will wait only for 10 ms after that it jumps from the loop and clear the previous data s stored in both uarts (UART0 AND UART1).My intention is that UART 1 will not wait for the remaining characters,after a particular time.The UART is waiting inside the loop for the remaining characters which never occur. so i need to flush the previously stored characters in the buffers(UART1 & 2) and need to start the program by accepting new character from UART0.
Code:
int UART0_getchar (void) {


      while (!(LPC_UART0->LSR & 0x01))

      {
    	 
      }
    }
      return (LPC_UART0->RBR);






    int UART1_getchar (void)
    {


      while (!(LPC_UART1->LSR & 0x01))

      {
        
          }
          return (LPC_UART1->RBR);
     }
 

write interrupts based

you can set the URXISEL bit so that the interrupt clears UART after some defined length.

for example,
U1STAbits.URXISEL = 0b11; // Interrupt flag bit is set when Receive Buffer is 4 full (i.e., has 4 data characters)
I used dsPIC30f5011
 

write like this

Code C - [expand]
1
2
3
4
Time = 0;
 
while (  (!(LPC_UART0->LSR & 0x01))   && (Time<LIMIT) )
Time++;


You can adjust the limit values with your baud rate ( for 1 byte delay)
 
Last edited:
Hi venkadeshm ,

How can i adjust the limit with baud rate?what is the use of that?can you please explain it for me?
my baud rate used for receiving and transmitting is 9600.

Thanks
Arun
 

The LIMIT is a macro and the value shd be more than the delay for 1 byte for example for 9600 baud rate

1 bit delay is 1/9600 and 10 bit delay (with start and stop bits) 1/960 sec.. so the value of limit is to remain in the while for atleast 2ms...
 
Hi
Iam attaching the UART function used in my program.please have a look at the code( the LPC UART init) and discribe the proper way to implement it


Code:
//****************************************************************************
// LPC122X Hardware setup
//
//****************************************************************************
// taken from NXP example code for LPB12000 to calculate baud rate setup
// This involves solving an equation with 2 or 3 unknowns depending on how you interpret
// the formula in the user manual.

// This is quite complex to solve so instead of writing from scratch, I've
// taken this example code including uart_set_divisors().
// This has been split into 2 routines: 1 for UART0 and another for UART1
// This allows me the option of changing the setup for one without compromising
// the other.

// The UART init routine has a precalculated default included for 115200
// If the baudrate is set to this in the defines, the precalculated version is used
// instead of calculating it.

// This calculating routine simply works so I've copied all the defines etc in a big block
// rather than work out which ones are not needed.

/**************************************************************************//**
 * $Id: lpc12xx_uart.c 541 2010-09-15 09:04:20Z nxp21428 $
 *
 * @file     lpc12xx_uart.c
 * @brief    Contains all functions support for UART firmware library on LPC12xx.
 * @version  1.0
 * @date     26. Sep. 2010
 * @author   NXP MCU Team
 *
 * @note
 * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved.
 *
 * @par
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
 ******************************************************************************/
/* Macro to define caculate */
#define UART_LOAD_DLL(div)        ((div) & 0xFF)
#define UART_LOAD_DLM(div)        (((div) >> 8) & 0xFF)
#define UART_FDR_DIVADDVAL(n)     ((uint32_t)(n&0x0F))      /* Pre-scaler divisor */
#define UART_FDR_MULVAL(n)        ((uint32_t)((n<<4)&0xF0)) /* Multiplier value */
#define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t)(n&0x0F))      /*receiver FIFO */
#define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t)((n>>8)&0x0F)) /*transmitter FIFO */

/* Macro to define parameter */
#define UART_ACCEPTED_BAUDRATE_ERROR  (1) /* Acceptable baudrate error, 1/2(n) percent */
#define UART_TX_FIFO_SIZE             (16)
#define UART_DEVICE_NUMBER            (2)

/* Macro to define bit mask */
#define UART_RBR_MASKBIT    ((uint8_t)0xFF) /* Received Buffer mask bit  */
#define UART_THR_MASKBIT    ((uint8_t)0xFF) /* Transmit Holding mask bit  */
#define UART_IER_BITMASK    ((uint32_t)(0x307)) /* IER normal bit mask */
#define UART_IER_BITMASK2   ((uint32_t)(0x38F)) /* IER include modem bit mask */
#define UART_IIR_BITMASK    ((uint32_t)(0x3CF)) /* IIR bit mask */
#define UART_FCR_BITMASK    ((uint8_t)(0xCF))   /* FCR bit mask */
#define UART_LCR_BITMASK    ((uint8_t)(0xFF))   /* LCR bit mask */
#define UART_MCR_BITMASK    ((uint8_t)(0xF3))   /* MCR bit mask */
#define UART_LSR_BITMASK    ((uint8_t)(0xFF))   /* LSR bit mask */
#define UART_MSR_BITMASK    ((uint8_t)(0xFF))   /* MSR register bit mask */
#define UART_SCR_BIMASK     ((uint8_t)(0xFF))   /* UART Scratch Pad bit mask */
#define UART_ACR_BITMASK    ((uint32_t)(0x307)) /* ACR bit mask */
#define UART_ICR_BITMASK    ((uint32_t)(0x3F))  /* IRDA bit mask */
#define UART_FDR_BITMASK    ((uint32_t)(0xFF))  /* FDR bit mask */
#define UART_TER_BITMASK    ((uint8_t)(0x80))   /* TER bit mask */
#define UART_RS485CTRL_BITMASK     ((uint32_t)(0x3F))  /* 485 CTRL bit mask */
#define UART_RS485ADRMATCH_BITMASK ((uint8_t)(0xFF))   /* 485 ADR bit mask */
#define UART_RS485DLY_BITMASK      ((uint8_t)(0xFF))   /* 485 DLY bit mask */
#define UART_FIFOLVL_BITMASK       ((uint32_t)(0x0F0F))/* 485 FIFOLVL bit mask */

/* Macro to define control bit */
#define UART_LCR_DLAB_EN        ((uint8_t)(1<<7))   /* DivisorLatchesAccess enable*/
#define UART_FCR_FIFO_EN        ((uint8_t)(1<<0))   /* FIFO enable */
#define UART_FCR_RX_RS          ((uint8_t)(1<<1))   /* FIFO RX reset */
#define UART_FCR_TX_RS          ((uint8_t)(1<<2))   /* FIFO TX reset */
#define UART_TER_TXEN           ((uint8_t)(1<<7))   /* Transmit enable bit */
#define UART_ACR_START          ((uint32_t)(1<<0))  /* Auto baudrate Start */
#define UART_ACR_ABEOINT_CLR    ((uint32_t)(1<<8))  /* Auto baudrate end INT clear */
#define UART_ACR_ABTOINT_CLR    ((uint32_t)(1<<9))  /* Auto baudrate Ttime-out INT clear */

//****************************************************************************
// RS485 UART setup and initialisation
// Uses UART0
//****************************************************************************

/*
  * @brief   Set uart baudrate
  * @param UARTx     Pointer to selected UART peripheral, should be LPC_UART0, LPC_UART1.
  * @param baudrate  baudrate number
  * @return status       SUCCESS or ERROR
  */
/**************************************************************************//**
 * $Id: lpc12xx_uart.c 541 2010-09-15 09:04:20Z nxp21428 $
 *
 * @file     lpc12xx_uart.c
 * @brief    Contains all functions support for UART firmware library on LPC12xx.
 * @version  1.0
 * @date     26. Sep. 2010
 * @author   NXP MCU Team
 *
 * @note
 * Copyright (C) 2010 NXP Semiconductors(NXP). All rights reserved.
 *
 * @par
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
 ******************************************************************************/
// Routine taken from example code from NXP for LPC1200
int uart0_set_divisors( uint32_t baudrate)
{


    uint32_t uClk = 0;
    uint32_t calcBaudrate = 0;
    uint32_t temp = 0;
    uint32_t errorStatus = 0;

    uint32_t mulFracDiv, dividerAddFracDiv;
    uint32_t diviser = 0 ;
    uint32_t mulFracDivOptimal = 1;
    uint32_t dividerAddOptimal = 0;
    uint32_t diviserOptimal = 0;

    uint32_t relativeError = 0;
    uint32_t relativeOptimalError = (baudrate >> UART_ACCEPTED_BAUDRATE_ERROR);

    /* get UART block clock */

        uClk = (MainClock/LPC_SYSCON->UART0CLKDIV)>>4; /* div by 16 */


//        uClk = (MainClock/LPC_SYSCON->UART1CLKDIV)>>4; /* div by 16 */


    /* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers
         * The formula is :
         * BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL)
         * It involves floating point calculations. That's the reason the formulae are adjusted with
         * Multiply and divide method.*/
    /* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions:
         * 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */
    for (dividerAddFracDiv = 0 ; dividerAddFracDiv < 15 ;dividerAddFracDiv++){
        for (mulFracDiv = (dividerAddFracDiv + 1) ; mulFracDiv <= 15 ;mulFracDiv++){
            temp = (mulFracDiv * uClk) / ((mulFracDiv + dividerAddFracDiv));

            diviser = temp / baudrate;
            if ((temp % baudrate) > (baudrate >> 1))
            diviser++;

            if (diviser > 2 && diviser < 65536){
                calcBaudrate = temp / diviser;

                if (calcBaudrate <= baudrate)
                  relativeError = baudrate - calcBaudrate;
                else
                  relativeError = calcBaudrate - baudrate;

                if ((relativeError < relativeOptimalError)){
                    mulFracDivOptimal = mulFracDiv ;
                    dividerAddOptimal = dividerAddFracDiv;
                    diviserOptimal = diviser;
                    relativeOptimalError = relativeError;
                    errorStatus = SUCCESS;
                }
            } /* End of if */
        } /* end of inner for loop */
    } /* end of outer for loop  */
// Now set up the UART0 registers
    if (errorStatus == SUCCESS){
        LPC_UART0->LCR |= UART_LCR_DLAB_EN;
        /* Then reset DLAB bit */
        while(LPC_UART0->LCR & UART_LCR_DLAB_EN){
        	LPC_UART0->DLL = UART_LOAD_DLL(diviserOptimal);
        	LPC_UART0->DLM = UART_LOAD_DLM(diviserOptimal);
        	LPC_UART0->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
        	LPC_UART0->FDR = (UART_FDR_MULVAL(mulFracDivOptimal) |\
                         UART_FDR_DIVADDVAL(dividerAddOptimal)) & UART_FDR_BITMASK;
        }
    }

    return errorStatus;
}


int uart1_set_divisors( uint32_t baudrate)
 {


     uint32_t uClk = 0;
     uint32_t calcBaudrate = 0;
     uint32_t temp = 0;
     uint32_t errorStatus = 0;

     uint32_t mulFracDiv, dividerAddFracDiv;
     uint32_t diviser = 0 ;
     uint32_t mulFracDivOptimal = 1;
     uint32_t dividerAddOptimal = 0;
     uint32_t diviserOptimal = 0;

     uint32_t relativeError = 0;
     uint32_t relativeOptimalError = (baudrate >> UART_ACCEPTED_BAUDRATE_ERROR);

     /* get UART block clock */

         uClk = (MainClock/LPC_SYSCON->UART0CLKDIV)>>4; /* div by 16 */


 //        uClk = (MainClock/LPC_SYSCON->UART1CLKDIV)>>4; /* div by 16 */


     /* In the Uart IP block, baud rate is calculated using FDR and DLL-DLM registers
          * The formula is :
          * BaudRate= uClk * (mulFracDiv/(mulFracDiv+dividerAddFracDiv) / (16 * (DLL)
          * It involves floating point calculations. That's the reason the formulae are adjusted with
          * Multiply and divide method.*/
     /* The value of mulFracDiv and dividerAddFracDiv should comply to the following expressions:
          * 0 < mulFracDiv <= 15, 0 <= dividerAddFracDiv <= 15 */
     for (dividerAddFracDiv = 0 ; dividerAddFracDiv < 15 ;dividerAddFracDiv++){
         for (mulFracDiv = (dividerAddFracDiv + 1) ; mulFracDiv <= 15 ;mulFracDiv++){
             temp = (mulFracDiv * uClk) / ((mulFracDiv + dividerAddFracDiv));

             diviser = temp / baudrate;
             if ((temp % baudrate) > (baudrate >> 1))
             diviser++;

             if (diviser > 2 && diviser < 65536){
                 calcBaudrate = temp / diviser;

                 if (calcBaudrate <= baudrate)
                   relativeError = baudrate - calcBaudrate;
                 else
                   relativeError = calcBaudrate - baudrate;

                 if ((relativeError < relativeOptimalError)){
                     mulFracDivOptimal = mulFracDiv ;
                     dividerAddOptimal = dividerAddFracDiv;
                     diviserOptimal = diviser;
                     relativeOptimalError = relativeError;
                     errorStatus = SUCCESS;
                 }
             } /* End of if */
         } /* end of inner for loop */
     } /* end of outer for loop  */
 // Now set up the UART0 registers
     if (errorStatus == SUCCESS){
         LPC_UART1->LCR |= UART_LCR_DLAB_EN;
         /* Then reset DLAB bit */
         while(LPC_UART1->LCR & UART_LCR_DLAB_EN){
         	LPC_UART1->DLL = UART_LOAD_DLL(diviserOptimal);
         	LPC_UART1->DLM = UART_LOAD_DLM(diviserOptimal);
         	LPC_UART1->LCR &= (~UART_LCR_DLAB_EN) & UART_LCR_BITMASK;
         	LPC_UART1->FDR = (UART_FDR_MULVAL(mulFracDivOptimal) |\
                          UART_FDR_DIVADDVAL(dividerAddOptimal)) & UART_FDR_BITMASK;
         }
     }

     return errorStatus;
 }
    /*----------------------------------------------------------------------------
      Initialize UART0 pins, Baudrate
     *----------------------------------------------------------------------------*/
    void UART0_init (void) {
      volatile uint32_t regVal;
      uint32_t  Fdiv;

      /* configure PINs GPIO0.1, GPIO0.2 for UART0 */
      LPC_SYSCON->SYSAHBCLKCTRL |= ((1UL << 31) |   /* enable clock for GPIO0     */
                                    (1UL << 16) );  /* enable clock for IOCON     */

      LPC_IOCON->PIO0_1 &= ~(7UL <<  0);            /* clear FUNC bits            */
      LPC_IOCON->PIO0_1 |=  (2UL <<  0);            /* P0.1 is RxD0               */
      LPC_IOCON->PIO0_2 &= ~(7UL <<  0);            /* clear FUNC bits            */
      LPC_IOCON->PIO0_2 |=  (2UL <<  0);            /* P0.2 is TxD0               */

      /* configure UART0 */
      LPC_SYSCON->SYSAHBCLKCTRL |=  (1UL << 12);    /* Enable clock to UART0      */
      LPC_SYSCON->UART0CLKDIV    =  (2UL <<  0);    /* UART0 clock =  CCLK / 2    */

      LPC_UART0->LCR = 0x83;                  /* 8 bits, no Parity, 1 Stop bit    */
      if(UART0_BAUDRATE == 115200){
      // This is where the UART is configured if it is 115200 DEBUG/TEST ONLY...
      LPC_UART0->LCR = 0x83;                  /* 8 bits, no Parity, 1 Stop bit    */
      LPC_UART0->DLL = 4;                     /* 115200 Baud Rate @ 12.0 MHZ PCLK */
      LPC_UART0->FDR = 0x85;                  /* FR 1.627, DIVADDVAL 5, MULVAL 8  */
      LPC_UART0->DLM = 0;                     /* High divisor latch = 0           */
      LPC_UART0->LCR = 0x03;                  /* DLAB = 0                         */
      }
      else
      {//This is where we calculate the baudrate settings using NXP sample software
    	  uart0_set_divisors(UART0_BAUDRATE); // let's go do the maths and work it all out
      }
      regVal = LPC_UART0->LSR;                      /* clear status register      */
    }
    void UART1_init (void) {
          volatile uint32_t regVal;
          	  	  uint32_t  Fdiv;


          /* configure PINs GPIO0.9, GPIO0.8 for UART1 */
          LPC_SYSCON->SYSAHBCLKCTRL |= ((1UL << 31) |   /* enable clock for GPIO0     */
                                        (1UL << 16) );  /* enable clock for IOCON     */

          LPC_IOCON->PIO0_9 &= ~(7UL <<  0);            /* clear FUNC bits            */
          LPC_IOCON->PIO0_9 |=  (2UL <<  0);            /* P0.1 is RxD0               */
          LPC_IOCON->PIO0_8 &= ~(7UL <<  0);            /* clear FUNC bits            */
          LPC_IOCON->PIO0_8 |=  (2UL <<  0);            /* P0.2 is TxD0               */

          /* configure UART0 */
          LPC_SYSCON->SYSAHBCLKCTRL |=  (1UL << 13);    /* Enable clock to UART1      */
          LPC_SYSCON->UART1CLKDIV    =  (2UL <<  0);    /* UART0 clock =  CCLK / 2    */

          LPC_UART1->LCR = 0x83;                  /* 8 bits, no Parity, 1 Stop bit    */
          if(UART1_BAUDRATE == 115200){
          // This is where the UART is configured if it is 115200 DEBUG/TEST ONLY...
          LPC_UART1->LCR = 0x83;                  /* 8 bits, no Parity, 1 Stop bit    */
          LPC_UART1->DLL = 4;                     /* 115200 Baud Rate @ 12.0 MHZ PCLK */
          LPC_UART1->FDR = 0x85;                  /* FR 1.627, DIVADDVAL 5, MULVAL 8  */
          LPC_UART1->DLM = 0;                     /* High divisor latch = 0           */
          LPC_UART1->LCR = 0x03;                  /* DLAB = 0                         */
          }
          else
          {//This is where we calculate the baudrate settings using NXP sample software
        	  uart1_set_divisors(UART1_BAUDRATE); // let's go do the maths and work it all out
          }
    }

    /*----------------------------------------------------------------------------
      Write character to Serial Port
     *----------------------------------------------------------------------------*/
    uint8_t UART0_sendchar (uint8_t c) {

      while (!(LPC_UART0->LSR & 0x20));
      LPC_UART0->THR = c;

      return (c);
    }
    uint8_t UART1_sendchar (uint8_t c) {

      while (!(LPC_UART1->LSR & 0x20));
      LPC_UART1->THR = c;

      return (c);
    }
    /*----------------------------------------------------------------------------
      Read character from Serial Port   (blocking read)
     *----------------------------------------------------------------------------*/

    // This is where the alarm check routines are inserted.
    // If there is no character to get, go check the alarm status.
    // If the alarm is triggered, interrupt the process and go send the new messages
    // The CPU has a 15 byte input buffer so incoming messages will get stored while the alarm is sorted out.
    // They will then get picked up after sorting out the alarm.
    // If this buffer is filled, then messages will get lost/ignored/dumped until the buffer is emptied.uint32_t delay[16

    //


    int UART0_getchar (void) {


      while (!(LPC_UART0->LSR & 0x01))

      {
    	 // msTicks = 0; // clear the timer;
      }
      return (LPC_UART0->RBR);
    }








    int UART1_getchar (void)
       {
    	     {

        	 Time = 0;
        	  
        	 while (  (!(LPC_UART0->LSR & 0x01))   && (Time<LIMIT) )
        	 Time++;
             }


             return (LPC_UART1->RBR);

       }

- - - Updated - - -

iam using a an internal oscillator of 12 Mhz.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
int UART1_getchar (void)
       {
        unsigned long time;
        
        Time = 0;
        while (  (!(LPC_UART0->LSR & 0x01))   && (Time<LIMIT) )  // waits till a char to receive or time for 2 bytes to receive
        Time++;
 
        if ( time  == LIMIT )                                                   // if time == LIMIT that means its exited the while with time delay
        retun FAIL;
 
        return (LPC_UART1->RBR);                                          // if successfully data received return received data
       }



using timer exact method


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int UART1_getchar (void)
       {
        unsigned long time;
        
        start timer;        // with a delay of more than 2 byte
 
        while (  (!(LPC_UART0->LSR & 0x01))   && (T0IF == 0) );  // waits till a char to receive or timer interrupt to set 
 
             if ( T0IF  == 1 )                                                 
         {
                 T0IF = 0;
                 return FAIL;
                 }
                
        return (LPC_UART1->RBR);                                          // if successfully data received return received data
       }

 
Hi venkadeshm
can i use delay(2) directly in Limit in first case?

- - - Updated - - -

Can you please explain the function of this
Code:
(LPC_UART0->LSR & 0x01)
 

you cant use delay(2) because it will just waste the time and never monitor the receiver status..

when the receive completes LSB of the LPC_UART0->LSR register is sets for getting the LSB we & with 00000001..
 
:lol::p:lol:

- - - Updated - - -

i am bit confused in choosing the value for the LIMIT
 

you cant just choose the value because you must to know the delay for executing while once so only you can choose number of times that while can execute for desired delay...

you can do trial and error or viewing the assembly conversion of while loop you can find number of cycles delay for it to execute..
 
i prefer the trial and error method, so i just defined
HTML:
#define LIMIT 2

- - - Updated - - -

Code:
#define END_COMMAND 0x00

Code:
main(void)

{
	
uint32_t *temp_ptr;

	int pelcod_payload_status = 0;
	int pelcod_message_type = 0;


	//int i = 0 ; // counter






// Initialise the LEDs
LED_init();

// Initialise the RS232/RS485 ports
UART0_init();
UART1_init();
while (FOREVER)

	{

		pelcod_payload_status = A_get_osiris_payload();


	switch (pelcod_payload_status)
	{

	case END_COMMAND:

	break; 	// Our work is done so leave this case statement,

	default:
	//Unknown error HELP!!!!!!
	//If we have got here something has seriously gone wrong as we should always get a valid error message
	break;
	}
	}
}

- - - Updated - - -

Code:
    int UART1_getchar (void)
           {
            unsigned long time;
            
            Time = 0;
            while (  (!(LPC_UART0->LSR & 0x01))   && (Time<LIMIT) )  // waits till a char to receive or time for 2 bytes to receive
            Time++;
     
            if ( time  == LIMIT )                                                   // if time == LIMIT that means its exited the while with time delay
            {
            	return END_COMMAND; //this will returns to the main loop,
            	
            }
     
            return (LPC_UART1->RBR);                                          // if successfully data received return received data
           }

- - - Updated - - -

Any comments plz Venkadeshm ????
 

i tried values 2000 and 5000, but now my U0 not rx charactor,waits in the while loop, iam going to implement the same function there too
Code:
    int UART0_getchar (void) {


      while (!(LPC_UART0->LSR & 0x01))
      {

      }
      return (LPC_UART0->RBR);
    }

- - - Updated - - -

Code:
int UART1_getchar (void)
       {
        unsigned long time;
        
        Time = 0;
        while (  (!(LPC_[B][U]UART0[/U][/B]->LSR & 0x01))   && (Time<LIMIT) )  // waits till a char to receive or time for 2 bytes to receive
        Time++;
 
        if ( time  == LIMIT )                                                   // if time == LIMIT that means its exited the while with time delay
        retun FAIL;
 
        return (LPC_UART1->RBR);                                          // if successfully data received return received data
       }
I think you mean UART 1 in this code coz iam rx via UART1
 

ERROR.png




the programs again stuks inside the while loop by incrementing the time, it is not checking the if time == limit. when the program got stuck, i went to debug mode and find out that the program loop between while and time++...



my project uses uart 0 and uart 1 for both reception and transmission 0 receives and transmit through uart1 and wait (uart1) for receiving the acknowledgement of the transmitted data.sometimes they will not send the ack or receives in error. so the UART 1 waits for a long time and the program get locks.only after the uart 1 rx an ack, the rx ack is transmitted via UART0, the cycle continuous...
 
Last edited:

Ya it will be there untill it reaches LIMIT value watch the time value.... and in some IDEs the uART wont function correctly in debug mode... And If you clearly explain your application I could say exactly what you want to do...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top