Saturday 7 January 2012

Interrupt Example Programs for Timer 0,1 and UART 0,1 using LPC2148

#include "LPC214x.H"
#include "stdio.h"
//CCLK=12xM=12x5=60MHZ
//PCLK=CCLK (VPBDIV=0x00)

#define RDR        0x01
#define THRE    0x20
#define RDA        0x04

void Timer0ISR(void)__irq;
void Timer1ISR(void)__irq;
void UART0ISR(void)__irq;
void UART1ISR(void)__irq;
void Exint0ISR(void)__irq;

unsigned char rxdat,rxdat1;
int txf,timer0_flag,timer1_flag,eint0_flag;
unsigned char a = 0;
unsigned short int fdiv;
         
void Init_PLL()
{
    //System Clock
    //PLLCFG = 0x00100100;              //p=2 (PSEL=01) and m=5-1 (MSEL=00100)
//    PLL0CFG = 0x00;     //0x0010 0010   //48Mhz m = 4-1 = 3 i.e 00010
    PLL0CFG = 0x23;                   //60Mhz m=5-1=4 i.e 00011
    PLL0CON = 0x01;
    PLL0FEED = 0xaa;
    PLL0FEED = 0x55;
    while((PLL0STAT & 0x400) == 0);
    PLL0CON = 0x03;
    PLL0FEED = 0xaa;
    PLL0FEED = 0x55;

    //USB clock
    //PLL1CFG = 0x00100011;            //p=2 (PSEL=01) and m=4-1 (MSEL=00011)
    PLL1CFG = 0x23;
    PLL1CON = 0x01;    
    PLL1FEED = 0xaa;
    PLL1FEED = 0x55;   
    while((PLL1STAT & 0x400) == 0);   
    PLL1CON = 0x03;                   
    PLL1FEED = 0xaa;
    PLL1FEED = 0x55;           
}

void Init_MAM(void)
{
    MAMTIM = 0x00000001;
    MAMCR  = 0x02;
}

void Init_VPB(void)
{
    VPBDIV = 0x00;
}
   
void Init_TIMER0(void)
{
    T0IR  = 0xff;         //clr the pending flags of interrupt
    //T0CTCR = 0x00;      //timer mode
    T0PR  = 1000;         //prescalar maximum count value keep it 1000 and change T0MR0
    T0PC  = 0;       
    T0MCR = 0x0003;       //MR0I=interrupt when TC=MR and reset
    T0MR0 = 1000;         //match the final value (using )
    //T0TC  = 0;
    T0TCR = 0x02;         //reset the timer
    T0TCR = 0x01;         //enable the timer
}

void Init_TIMER1(void)
{
    T1IR  = 0xff;         //clr the pending flags of interrupt
    //T1CTCR = 0x00;      //timer mode
    T1PR  = 1000;         //prescalar maximum count value keep it 1000 and change T0MR1
    T1PC  = 0;       
    T1MCR = 0x0003;       //MR0I=interrupt when TC=MR and reset
    T1MR0 = 1000;         //match the final value (using )
    //T1TC  = 0;
    T1TCR = 0x02;         //reset the timer
    T1TCR = 0x01;         //enable the timer
}

void Init_EXTINT0(void)
{
    EXTINT    = 0x01;     //clr interrupt bit
    INTWAKE   = 0x0000;
    EXTMODE   = 0x01;     //EINT0 edge sensitive
    EXTPOLAR  = 0x01;     //EINT0 rising edge
}

void Init_UART0(void)
{
    U0LCR = 0X83;
    U0FDR = 0xa1;
    fdiv  = ((12000000 * 10)/(16 * 9600 * 11));
    U0DLM= fdiv/256;
    U0DLL = fdiv%256;
    U0LCR = 0x03;
    U0FCR = 0x01;
    U0IER = 0x00000003;    //RI and TI interrupt
}

void Init_UART1(void)
{
/*        formula for BR calculation:    =PCLK x mulval /
                            [(16 x (16 x U0DLM + U0DLL))x(MULVAL + DIVADDVAL)
        9609 = 48Mhz x 5 / [(16 x (16 x 0 + 223)) x (5 + 7)]    */
    U1LCR = 0X83;
    U1FDR = 0xa1;
    fdiv  = ((12000000 * 10)/(16 * 9600 * 11));
    U1DLM= fdiv/256;
    U1DLL = fdiv%256;
    U1LCR = 0x03;
    U1FCR = 0x01;
    U1IER = 0x00000003;    //RI and TI interrupt
}

void Init_VIC(void)
{
    VICIntSelect = 0x00000000;          //select timer0 interrupt ad IRQ i.e bit 4=0
    //VICDefVectAddr  = (unsigned long int)timer0ISR; do not use when more than one interrupts are used
    VICVectAddr0 = (unsigned long int)Timer0ISR;
    VICVectCntl0 = 0x24;                 //bit 5 is enabled the slot to produce unique interrupt address for enabled timer0 interrupt
    VICIntEnable = 0x00000010;          //enable timer0 interrupt

    //VICDefVectAddr  = (unsigned long int)timer0ISR; do not use when more than one interrupts are used
    VICVectAddr1 = (unsigned long int)Timer1ISR;
    VICVectCntl1 = 0x25;                 //bit 5 is enabled the slot to produce unique interrupt address for enabled timer0 interrupt
    VICIntEnable |= 0x00000020;          //enable timer0 interrupt

    VICVectCntl2 = 0x26;
    VICVectAddr2 = (unsigned long int)UART0ISR;
    VICIntEnable |= 0x00000040;          //enable UART0 interrupt


    VICVectAddr3 = (unsigned long int)UART1ISR;
    VICVectCntl3 = 0x27;      
    VICIntEnable |= 0x00000080;

    VICIntEnable |= 0x00004000;          //enable EINT0 interrupt
    VICIntSelect = 0x00000001;          //select EINT0 interrupt as IRQ i.e bit 14=0
    VICVectAddr4 = (unsigned long int)Exint0ISR;
    VICVectCntl4 = 0x2e;
}

void Init_PORT(void)
{
    PINSEL0 = 0x00050005;          //p0.15 and p0.7 as GPIO P0.1=RXD P0.0=TXD
    PINSEL1 = 0x00000000;          //p0.16 as EINT0
    PINSEL2 = 0x00000000;
    IO0DIR  = 0xffffffff;
    IO0CLR  = 0xffffffff;
}

void delay(void)
{
    unsigned short int i;
    for(i=0;i<50000;i++);
}

int main(void)
{
    Init_PLL();
    Init_MAM();
    Init_VPB();
    Init_PORT();   
    Init_TIMER0();
    Init_TIMER1();
    Init_EXTINT0();
    Init_UART0();
    Init_UART1();
    Init_VIC();
                   
     while(1)
      {
           if(rxdat == 'A')
        {
            IO0SET |= 0x00004000;
            while(!(U0LSR & THRE));
                U0THR = rxdat;
            rxdat = 255;
        }
           if(rxdat == 'B')
        {
             IO0CLR |= 0x00004000;
            while(!(U0LSR & THRE));
                U0THR = rxdat;
            rxdat = 255;
        }   
    }
}

void Timer0ISR(void)__irq
{
    T0IR = 0xff;
    if(timer0_flag)
        IO0SET |= 0x00001000;
    else
        IO0CLR |= 0x00001000;   
    timer0_flag = ~timer0_flag;   
    VICVectAddr = 0x00;
}

void Timer1ISR(void)__irq
{
    T1IR = 0xff;
    if(timer1_flag)
        IO0SET |= 0x000000010;
    else
        IO0CLR |= 0x000000010;   
    timer1_flag = ~timer1_flag;   
    VICVectAddr = 0x00;
}

void Exint0ISR(void)__irq
{
    EXTINT = 0x01;   
    if(eint0_flag)
        IO0SET |= 0x00000080;
    else
        IO0CLR |= 0x00000080;   
    eint0_flag = ~eint0_flag;   
    VICVectAddr = 0x00;
}

void UART0ISR(void)__irq
{
    if(U0IIR & RDA)
        rxdat = U0RBR;
    VICVectAddr = 0x00;
}
                               
void UART1ISR(void)__irq
{       
    if(U1IIR & RDA)
        rxdat = U1RBR;
    VICVectAddr = 0x00;
}

Thursday 5 January 2012

GSM CME Error List


CME ERROR's (GSM Equipment related codes)
Error
Description
CME ERROR: 0
Phone failure
CME ERROR: 1
No connection to phone
CME ERROR: 2
Phone adapter link reserved
CME ERROR: 3
Operation not allowed
CME ERROR: 4
Operation not supported
CME ERROR: 5
PH_SIM PIN required
CME ERROR: 6
PH_FSIM PIN required
CME ERROR: 7
PH_FSIM PUK required
CME ERROR: 10
SIM not inserted
CME ERROR: 11
SIM PIN required
CME ERROR: 12
SIM PUK required
CME ERROR: 13
SIM failure
CME ERROR: 14
SIM busy
CME ERROR: 15
SIM wrong
CME ERROR: 16
Incorrect password
CME ERROR: 17
SIM PIN2 required
CME ERROR: 18
SIM PUK2 required
CME ERROR: 20
Memory full
CME ERROR: 21
Invalid index
CME ERROR: 22
Not found
CME ERROR: 23
Memory failure
CME ERROR: 24
Text string too long
CME ERROR: 25
Invalid characters in text string
CME ERROR: 26
Dial string too long
CME ERROR: 27
Invalid characters in dial string
CME ERROR: 30
No network service
CME ERROR: 31
Network timeout
CME ERROR: 32
Network not allowed, emergency calls only
CME ERROR: 40
Network personalization PIN required
CME ERROR: 41
Network personalization PUK required
CME ERROR: 42
Network subset personalization PIN required
CME ERROR: 43
Network subset personalization PUK required
CME ERROR: 44
Service provider personalization PIN required
CME ERROR: 45
Service provider personalization PUK required
CME ERROR: 46
Corporate personalization PIN required
CME ERROR: 47
Corporate personalization PUK required
CME ERROR: 48
PH-SIM PUK required
CME ERROR: 100
Unknown error
CME ERROR: 103
Illegal MS
CME ERROR: 106
Illegal ME
CME ERROR: 107
GPRS services not allowed
CME ERROR: 111
PLMN not allowed
CME ERROR: 112
Location area not allowed
CME ERROR: 113
Roaming not allowed in this location area
CME ERROR: 126
Operation temporary not allowed
CME ERROR: 132
Service operation not supported
CME ERROR: 133
Requested service option not subscribed
CME ERROR: 134
Service option temporary out of order
CME ERROR: 148
Unspecified GPRS error
CME ERROR: 149
PDP authentication failure
CME ERROR: 150
Invalid mobile class
CME ERROR: 256
Operation temporarily not allowed
CME ERROR: 257
Call barred
CME ERROR: 258
Phone is busy
CME ERROR: 259
User abort
CME ERROR: 260
Invalid dial string
CME ERROR: 261
SS not executed
CME ERROR: 262
SIM Blocked
CME ERROR: 263
Invalid block
CME ERROR: 772
SIM powered down
CMS ERROR's (GSM Network related codes)
Error
Description
CMS ERROR: 1
Unassigned number
CMS ERROR: 8
Operator determined barring
CMS ERROR: 10
Call bared
CMS ERROR: 21
Short message transfer rejected
CMS ERROR: 27
Destination out of service
CMS ERROR: 28
Unidentified subscriber
CMS ERROR: 29
Facility rejected
CMS ERROR: 30
Unknown subscriber
CMS ERROR: 38
Network out of order
CMS ERROR: 41
Temporary failure
CMS ERROR: 42
Congestion
CMS ERROR: 47
Recourses unavailable
CMS ERROR: 50
Requested facility not subscribed
CMS ERROR: 69
Requested facility not implemented
CMS ERROR: 81
Invalid short message transfer reference value
CMS ERROR: 95
Invalid message unspecified
CMS ERROR: 96
Invalid mandatory information
CMS ERROR: 97
Message type non existent or not implemented
CMS ERROR: 98
Message not compatible with short message protocol
CMS ERROR: 99
Information element non-existent or not implemented
CMS ERROR: 111
Protocol error, unspecified
CMS ERROR: 127
Internetworking , unspecified
CMS ERROR: 128
Telematic inter networking not supported
CMS ERROR: 129
Short message type 0 not supported
CMS ERROR: 130
Cannot replace short message
CMS ERROR: 143
Unspecified TP-PID error
CMS ERROR: 144
Data code scheme not supported
CMS ERROR: 145
Message class not supported
CMS ERROR: 159
Unspecified TP-DCS error
CMS ERROR: 160
Command cannot be actioned
CMS ERROR: 161
Command unsupported
CMS ERROR: 175
Unspecified TP-Command error
CMS ERROR: 176
TPDU not supported
CMS ERROR: 192
SC busy
CMS ERROR: 193
No SC subscription
CMS ERROR: 194
SC System failure
CMS ERROR: 195
Invalid SME address
CMS ERROR: 196
Destination SME barred
CMS ERROR: 197
SM Rejected-Duplicate SM
CMS ERROR: 198
TP-VPF not supported
CMS ERROR: 199
TP-VP not supported
CMS ERROR: 208
D0 SIM SMS Storage full
CMS ERROR: 209
No SMS Storage capability in SIM
CMS ERROR: 210
Error in MS
CMS ERROR: 211
Memory capacity exceeded
CMS ERROR: 212
SIM application toolkit busy
CMS ERROR: 213
SIM data download error
CMS ERROR: 255
Unspecified error cause
CMS ERROR: 300
ME Failure
CMS ERROR: 301
SMS service of ME reserved
CMS ERROR: 302
Operation not allowed
CMS ERROR: 303
Operation not supported
CMS ERROR: 304
Invalid PDU mode parameter
CMS ERROR: 305
Invalid Text mode parameter
CMS ERROR: 310
SIM not inserted
CMS ERROR: 311
SIM PIN required
CMS ERROR: 312
PH-SIM PIN required
CMS ERROR: 313
SIM failure
CMS ERROR: 314
SIM busy
CMS ERROR: 315
SIM wrong
CMS ERROR: 316
SIM PUK required
CMS ERROR: 317
SIM PIN2 required
CMS ERROR: 318
SIM PUK2 required
CMS ERROR: 320
Memory failure
CMS ERROR: 321
Invalid memory index
CMS ERROR: 322
Memory full
CMS ERROR: 330
SMSC address unknown
CMS ERROR: 331
No network service
CMS ERROR: 332
Network timeout
CMS ERROR: 340
No +CNMA expected
CMS ERROR: 500
Unknown error
CMS ERROR: 512
User abort
CMS ERROR: 513
Unable to store
CMS ERROR: 514
Invalid Status
CMS ERROR: 515
Device busy or Invalid Character in string
CMS ERROR: 516
Invalid length
CMS ERROR: 517
Invalid character in PDU
CMS ERROR: 518
Invalid parameter
CMS ERROR: 519
Invalid length or character
CMS ERROR: 520
Invalid character in text
CMS ERROR: 521
Timer expired
CMS ERROR: 522
Operation temporary not allowed
CMS ERROR: 532
SIM not ready
CMS ERROR: 534
Cell Broadcast error unknown
CMS ERROR: 535
Protocol stack busy
CMS ERROR: 538
Invalid parameter