PIC32 two uart interrupts

Discussion in 'Embedded Systems and Microcontrollers' started by varunme, Apr 18, 2016.

  1. varunme

    Thread Starter Member

    Sep 29, 2011
    59
    0
    I have the below program, in which data is not coming to second UART,

    first uart is working,


    someone kindly help me


    Code (Text):
    1. void main() {
    2.  
    3.     AD1PCFG = 0xFFFD;   // Configure AN pins as digital I/O
    4.     JTAGEN_bit = 0;     // Disable JTAG
    5.  
    6.     TRISB = 0x0000000F;
    7.     TRISD = 0x04;
    8.     TRISF = 0x10;
    9.     TRISG = 0x80;
    10.  
    11.     LATB = 0x00;
    12.  
    13.     LCD_Init();
    14.     LCD_Cmd(_LCD_CURSOR_OFF);
    15.     LCD_Cmd(_LCD_CLEAR);
    16.  
    17.     LCD_Out(1,1,"     Green House    ");
    18.     LCD_Out(2,1,"       Monitor      ");
    19.  
    20.     UART2_Init(9600); // Initialize Soft UART at 14400 bps
    21.     Delay_ms(200);
    22.  
    23.     UART1_Init(9600);
    24.     Delay_ms(200);
    25.  
    26.     DHT11_Init();
    27.    
    28.     U1IP0_bit = 0;                     // Set UART2 interrupt
    29.     U1IP1_bit = 1;                     // Set interrupt priorities
    30.     U1IP2_bit = 1;                     // Set UART2 interrupt to level 6
    31.  
    32.     U1RXIE_bit = 1;
    33.  
    34.     EnableInterrupts();
    35.              
    36.     U1RXIF_bit = 0;
    37.  
    38.     GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
    39.     GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
    40.     GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand4, &gsmBufferIndex, &gsmAttempt, 1);
    41.     GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand5, &gsmBufferIndex, &gsmAttempt, 1);
    42.     GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand6, &gsmBufferIndex, &gsmAttempt, 1);
    43.  
    44.     InitTimer2_3();
    45.  
    46.     Delay_ms(2000);
    47.     LCD_Cmd(_LCD_CLEAR);
    48.  
    49.     ADC1_Init();                   // Initialize ADC module
    50.     Delay_ms(100);
    51.    
    52.     while(1) {
    53.  
    54.         moisture = (unsigned long)ADC1_Get_Sample(0) * 80 / 1023;
    55.         Delay_ms(50);
    56.  
    57.         lightIntensity = (unsigned int)ADC1_Get_Sample(1);
    58.         Delay_ms(50);
    59.  
    60.         if(!toggleDisplay) {
    61.             LCD_Out(1,1,"Light: ");
    62.             LCD_Out(2,1,"Moisture: ");
    63.             IntToStr(lightIntensity, text);
    64.             Ltrim(str);
    65.             Rtrim(str);
    66.             LCD_Out(1,13,text);
    67.             memset(text, '\0', sizeof(text));
    68.             strcat(text, "Light Intensity: ");
    69.             IntToStr(lightIntensity, msg);
    70.             Ltrim(msg);
    71.             Rtrim(msg);
    72.             strcat(text, msg);
    73.             strcat(text, "\r\n");
    74.             UART2_Write_Text(text);
    75.         }
    76.  
    77.         if(!toggleDisplay) {
    78.             LongToStr(moisture, text);
    79.             Ltrim(text);
    80.             Rtrim(text);
    81.             strcat(text, "%");
    82.             LCD_Out(2,13,text);
    83.             strcat(text, " %\r\n");
    84.             UART2_Write_Text(text);
    85.         }
    86.  
    87.         DHT11_Start();
    88.         DHT11_Read();
    89.  
    90.         //if(DHT11_Checksum == ((DHT11_Temperature >> 8) + (DHT11_Humidity >> 8) + (DHT11_Temperature & 0xFF) + (DHT11_Humidity & 0xFF))) {
    91.  
    92.             if(toggleDisplay) {
    93.                 LCD_Out(3,1,"Temperature:");
    94.                 LCD_Out(4,1,"Humidity: ");
    95.  
    96.                 ByteToStr((DHT11_Temperature >> 8), text);
    97.                 Ltrim(text);
    98.                 Rtrim(text);
    99.                 LCD_Out(3,13,text);
    100.                 CustomChar(3,16);
    101.                 LCD_Out(3,17,"C");
    102.                 strcat(text, " degree C\r\n");
    103.                 UART2_Write_Text(text);
    104.  
    105.                 ByteToStr((DHT11_Humidity >> 8), text);
    106.                 Ltrim(text);
    107.                 Rtrim(text);
    108.                 strcat(text, "%");
    109.                 LCD_Out(4,13,text);
    110.                 strcat(text, " %\r\n");
    111.                 UART2_Write_Text(text);
    112.             }
    113.         //}
    114.  
    115.         if((((DHT11_Humidity >> 8) > 85) || (moisture  > 60)) && executeOnce1 == 0) {
    116.               Humidity_Pump = OFF;
    117.               CopyConst2Ram(sms, msg6);
    118.               Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    119.  
    120.               executeOnce1 = 1;
    121.         }
    122.         else if((((DHT11_Humidity >> 8) < 30) || (moisture  < 30)) && executeOnce1 == 1) {
    123.               Humidity_Pump = ON;
    124.               CopyConst2Ram(sms, msg5);
    125.               Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    126.  
    127.               executeOnce1 = 0;
    128.         }
    129.  
    130.         if(((DHT11_Temperature >> 8) > 30) && executeOnce2 == 0) {
    131.              CopyConst2Ram(sms, msg9);
    132.              Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    133.  
    134.              executeOnce2 = 1;
    135.         }
    136.         else if(((DHT11_Temperature >> 8) < 30) && executeOnce2 == 1) {
    137.              executeOnce2 = 0;
    138.         }
    139.  
    140.         if((moisture < 30) && executeOnce3 == 0) {
    141.             Moisture_Pump = ON;
    142.             CopyConst2Ram(sms, msg7);
    143.             Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    144.  
    145.             executeOnce3 = 1;
    146.         }
    147.         else if((moisture > 40) && executeOnce3 == 1) {
    148.             Moisture_Pump = OFF;
    149.             CopyConst2Ram(sms, msg8);
    150.             Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    151.  
    152.             executeOnce3 = 0;
    153.         }
    154.  
    155.         if(((moisture > 30) && (moisture < 40)) && executeOnce4 == 0) {
    156.             Moisture_Pump = ON;
    157.             CopyConst2Ram(sms, msg7);
    158.             Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    159.  
    160.             executeOnce4 = 1;
    161.         }
    162.         else if((moisture < 40) && executeOnce4 == 1) {
    163.             Moisture_Pump = OFF;
    164.             CopyConst2Ram(sms, msg8);
    165.             Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);
    166.  
    167.             executeOnce4 = 0;
    168.         }
    169.     }
    170. }


    Is the second UART initliaization correct?


    Code (Text):
    1.     UART2_Init(9600); // Initialize Soft UART at 14400 bps
    2.     Delay_ms(200);
    3.  
    4.     UART1_Init(9600);
    5.     Delay_ms(200);
    6.  
    7.     DHT11_Init();
    8.    
    9.     U1IP0_bit = 0;                     // Set UART2 interrupt
    10.     U1IP1_bit = 1;                     // Set interrupt priorities
    11.     U1IP2_bit = 1;                     // Set UART2 interrupt to level 6
    12.  
    13.     U1RXIE_bit = 1;
    14.  
    15.     EnableInterrupts();
    16.              
    17.     U1RXIF_bit = 0;
     
Loading...