Problem in LPC2124 timer and uart

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

Problem in LPC2124 timer and uart

1,234 Views
ayyappansekar
Contributor I

I am working in LPC2124 controller , but now problem issue is sending serial data communication(uart) ,not properly received the application end.

When did enable the both  UART and TIMER in same time , the sending serial data is stop in particular time,without timer enable its receiving serial data(Uart) working good.

I think both(timer&uart) interrupt occur in at same time,so that may be problem is coming. 

Please if you any sample code for using both timer and uart at time configuration file.

kindly for your reference attached code please find it.

Labels (1)
0 Kudos
3 Replies

852 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi,

You could try assigning proper priorities to each interrupt according with your application requirements. Please take a look at following application notes regarding implementing a UART, code hints, and nesting interrupts on LPC2xxx devices:

AN10689 “Full-duplex software UART for LPC2000”

AN10404 “Initialization code/hints for the LPC2000 family”

AN10381 “Nesting of interrupts in the LPC2000”

 

Hope this will be useful for you.

Best regards!

/Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

853 Views
ayyappansekar
Contributor I

Thank you for your reply .

As per your guide i am adding PLL and vector configuration in my code but again the problem is Same , Please kindly for your reference attaching code here, please find it .if im missing anything configuration Pl let me know else correct them send it workout correct code.

Regards

Ayyappan.

/*-------------------------------------------------------------------------------------------------------------------------------*/
#include <iolpc2124.h>
#include <intrinsics.h>
#include "filters.h"

#include<math.h>

// UART0 Macro declaration
#define DESIRED_BAUDRATE 28800
#define CRYSTAL_FREQUENCY_IN_HZ 16000000
#define PCLK   CRYSTAL_FREQUENCY_IN_HZ      
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))

// UART1 Macro declaration
#define DESIRED_BAUDRATE1 9600   
#define DIVISOR1 (PCLK/(16*DESIRED_BAUDRATE1))


unsigned char get,get1;   
   
void test(void);
void TMER0_INITIALIZE(void);
void delay_ms(unsigned int value);


__irq __arm void T0_Handler(void);
__irq __arm void IRQ_default(void) ;

__irq __arm void UART0(void);
__irq __arm void UART1(void);


void delay(unsigned int dly);
void delay(unsigned int dly)
{
  int k;
  for(k=0;k<dly;k++);   
}


void Uone_send(unsigned char dat);
void Uone_send(unsigned char dat)
{
   while (!(U1LSR &0x20));
    U1THR = dat;
             delay(50);
 
}


/**************ECG*****************************/
//Type Definitions -these are tailored to fit given bit sizes storage requests to the actual bit size preference of the target
typedef unsigned int            U8;             /*  8 bit unsigned UPGRADE*/
typedef signed int              S8;             /*  8 bit signed   UPGRADE*/
typedef unsigned int            U16;            /* 16 bit unsigned */
typedef signed int              S16;            /* 16 bit signed */
//typedef unsigned long int       U32;            /* 32 bit unsigned */
//typedef signed long int         S32;            /* 32 bit signed */

// user defined function prototype declaration

void send_serial_data(unsigned char serial);
void send_serial_data_1(unsigned char serial);
static unsigned short ADC_Read(unsigned char ch);
void adc_serial_tx(unsigned int ch);

void adc_serial_tx(unsigned int ch)
{  
    unsigned long int  t100,t10,t1,temp;
   // t10000 = ch / 10000;
   // temp   = ch % 10000;
    //t1000 = ch   / 1000;                 
    temp  =ch  % 1000;                 
    t100  = temp / 100;                 
    temp  = temp % 100;                
    t10   = temp / 10;                  
    t1    = temp % 10;                 
    //send_serial_data(t10000+0x30);
    //send_serial_data(t1000+0x30);
    send_serial_data(t100 +0x30);
    send_serial_data(t10+0x30);
    send_serial_data(t1+0x30);
}
void send_serial_data(unsigned char serial)
{  
  while((U0LSR & 0x20)==0);
      U0THR = serial;      
}
void send_serial_data_1(unsigned char serial)
{  
  while((U1LSR & 0x20)==0);
      U1THR = serial;      
}

static unsigned short ADC_Read(unsigned char ch)
{
unsigned int i;
ADCR = 0x00200300 | ch; // Init ADC (Pclk = 12MHz) and select channel
ADCR |= 0x01000000; // Start A/D Conversion

do
{
i = ADDR; // Read A/D Data Register
} while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
return (i >> 6) & 0x03FF; // bit 6:15 is 10 bit AD value
}
int putchar0(int ch);
int putchar0(int ch)
{
   if (ch == '\n')
    {
    while (!(U0LSR & 0x20));
    U0THR = 0x0d;
    }
   while (!(U0LSR & 0x20));
   return (U0THR = ch);
}


#pragma vector=0x18
__irq __arm void IRQ_ISR_Handler (void)
{
  void (*interrupt_function)();
  unsigned int vector;

  vector = VICVectAddr;     // Get interrupt vector.
  interrupt_function = (void(*)())vector;
  (*interrupt_function)();  // Call vectored interrupt function thru pointer
  VICVectAddr = 0;          // Clear interrupt in VIC
}

int putchar1(int ch)
{
   if (ch == '\n')
    {
    while (!(U1LSR & 0x20));
    U1THR = 0x0d;
    }
   while (!(U1LSR & 0x20));
   return (U1THR = ch);
}

__irq __arm void UART0()
{
    
  unsigned long int a;
    __disable_interrupt();
    a = U0IIR;             // 0000 0000 0000 0000    0000 0000 0000 0001
    a = a >> 1;            // 0000 0000 0000 0000    0000 0000 0000 0010 // skip pending bit in IIR
    a = a & 0x00000002;    // 0000 0000 0000 0000    0000 0000 0000 0010     
    if(a==0x00000002)      // Receive Data Available
    {
        get = U0RBR;    
       // putchar1(get);
    }
    __enable_interrupt(); // Global interrupt enable
     VICVectAddr = 0;        // Dummy write to transfer the control to main program
     return;
}
__irq __arm void UART1()
{
  unsigned long int a;
  unsigned char getdata;   
    __disable_interrupt();
    a = U1IIR;             // 0000 0000 0000 0000    0000 0000 0000 0001
    a = a >> 1;            // 0000 0000 0000 0000    0000 0000 0000 0010 // skip pending bit in IIR
    a = a & 0x00000002;    // 0000 0000 0000 0000    0000 0000 0000 0010     
    if(a==0x00000002)      // Receive Data Available
    {
      if(u1_rv_cmd==0)
      {
        getdata = U1RBR;
        u1_Rx_buf[u1_ptr++]=getdata;;
        if(u1_Rx_buf[1]== u1_ptr)
        {
          
            u1_rv_cmd=1;
        }
      }// putchar0(get1);
    }
    __enable_interrupt(); // Global interrupt enable
     VICVectAddr = 0;        // Dummy write to transfer the control to main program
     return;
}
/***************************UART CONFIGURATION SECTION END********************************/

/****************************** START OF MAIN FUNCTION************************************/
void main(void)
{
      PINSEL0 = 0x00050005;
      PINSEL1 = 0x00000000;
      IO0DIR  = 0xffffffff;
      
      PINSEL2  = 0x00000000;
      IO1DIR   = 0x10000000;        // BUZZER
      IO1SET|=(1<<28);
   
      
      
      
      
  //    PCONP = 0x00000000; //turn off all peripherals
     // VPBDIV = 0x01;
  //    PCONP |= (1<<1);
      
  /*   // MAMTIM =0x1;   
     // MAMCR = 0x2;  
      
 
  //Setzt Frequenz des Kerns
      PLLCFG = 0x00000024;
      PLLFEED = 0x000000AA;
      PLLFEED = 0x00000055;
     
      PLLCON = (1<<0);
      PLLFEED = 0x000000AA;
      PLLFEED = 0x00000055;

      while(!(PLLSTAT & 0x00000400));
    
     PLLCON = 0x00000003;
    
     PLLFEED = 0x000000AA;
     PLLFEED = 0x00000055;
    //VPBDIV = 0x00000001;
 
      
     
      */
      
    //test();
      
   
      VPBDIV_bit.VPBDIV=1;   //pclk = cclk
      U0LCR = 0x83;  
      U0DLL = DIVISOR % 256;
      U0DLM = DIVISOR / 256;
      U0LCR = 0x03;
      U0FCR = 0x05;  
      U0IER=0x01;
      
      U1LCR = 0x83;  
      U1DLL = DIVISOR1 % 256;
      U1DLM = DIVISOR1 / 256;
      U1LCR = 0x03;
      U1FCR = 0x05;  
      U1IER=0x01;
      VICIntSelect &= ~(1<<VIC_UART0);            // Timer 0 intrpt is an IRQ
      VICVectAddr3 = (unsigned int)&UART0; // Install ISR in VIC addr slot
      VICVectCntl3 = 0x20 | VIC_UART0;            // IRQ type, TIMER 0 int enabled
      VICIntEnable |= (1<<VIC_UART0);  
      
      
      VICIntSelect &= ~(1<<VIC_UART1);            // Timer 0 intrpt is an IRQ
      VICVectAddr1 = (unsigned int)&UART1; // Install ISR in VIC addr slot
      VICVectCntl1 = 0x20 | VIC_UART1;            // IRQ type, TIMER 0 int enabled
      VICIntEnable |= (1<<VIC_UART1);             // Turn on Timer0 Interrupt
      PICQRSDet(0,1);
      __enable_interrupt(); // Global interrupt enable
      
       TMER0_INITIALIZE();
       while(1)
    {  
      
      
          switch(get)  // start of switch
          {
            
            case 'Y':// communication  handshaking commands Y
                {
                  get=0;
                  putchar0('[');
                  putchar0('Z');                             //Z
                  putchar0(']');
                  putchar0('@');
                }
                
                break;
                
          }
    }
    
}              
     

/******************************END OF MAIN FUNCTION****************************************************/

void test()
{
     
        IO1SET |=(1<<28);
        delay_ms(0);
       
        IO1CLR |=(1<<28);
        delay_ms(0);
      
        
     
}  

void TMER0_INITIALIZE(void)
{               
    PCONP |= (1<<1); //enable TIMER0 clock
    T0TCR = 0x00; //stop TIMER0
    T0TCR = 0x02; //reset counters
    T0TCR = 0x00; //release the reset
    T0IR = 0x0FF; //clear all TIMER0 flags
    T0PR = 0x00000000; //no prescaler
    T0MR0 = 12499; // 1msec match count  ; (12MHz * 1ms)-1;
    T0MCR = 2; //reset TIMER0 on MR0
    T0EMR = 0x0008; //drive MAT0.3 high
    T0TCR = 0x01; //let TIMER0 run
//VIC setup
   VICIntSelect = 0x00000000; //all interrupts are IRQs
 //  VICIntEnClr = 0xFFFFFFF0; //disable all interrupts
   VICVectCntl0 = 0x20 | 4; //use slot 0 for TIMER0
   VICVectAddr0 = (unsigned long)T0_Handler; //set the TIMER0 handler
   VICDefVectAddr = (unsigned long)IRQ_default; //set the default handler
   VICIntEnable = 1<<4; //enable TIMER0 interrupts
        
        
        }

__irq __arm void T0_Handler(void)
{
 
 unsigned int count = 0;
 count =count+1;
 if (count ==500)
 {
     IO1CLR |=(1<<28);
     putchar0('1');
     }
 else if(count==1000)
 {
    IO1SET |=(1<<28);
     putchar0('2');
    count=0;
}
      T0IR            = 0x01;  
      VICVectAddr = 0;        // Dummy write to transfer the control to main program
      return;   

}

__irq __arm void IRQ_default(void)     //default IRQ isr
{
VICVectAddr=0xFF; //update the VIC
}

0 Kudos

853 Views
ayyappansekar
Contributor I

hai to all,

                 Early i am using lpc2378 micro controller more than 6 yrs but now this controller not available too long in future design,so that now looking for same compatibility in LPC series replacement, please anyone suggest to me which one i am going to select for same LPC2378.

0 Kudos