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.

UART data not coming to second uart port

Status
Not open for further replies.

varunme

Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Activity points
5,764
I have a program which sends data to uart and lCD, the program sends data to first uart, but no communication with the second

someone kindly help

Code:
void main() {

    AD1PCFG = 0xFFFD;   // Configure AN pins as digital I/O
    JTAGEN_bit = 0;     // Disable JTAG

    TRISB = 0x0000000F;
    TRISD = 0x04;
    TRISF = 0x10;
    TRISG = 0x80;

    LATB = 0x00;

    LCD_Init();
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);

    LCD_Out(1,1,"     Green House    ");
    LCD_Out(2,1,"       Monitor      ");

    UART2_Init(9600); // Initialize Soft UART at 14400 bps
    Delay_ms(200);

    UART1_Init(9600);
    Delay_ms(200);

    DHT11_Init();
    
    U1IP0_bit = 0;                     // Set UART2 interrupt
    U1IP1_bit = 1;                     // Set interrupt priorities
    U1IP2_bit = 1;                     // Set UART2 interrupt to level 6

    U1RXIE_bit = 1;

    EnableInterrupts();
              
    U1RXIF_bit = 0;

    GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
    GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand1, &gsmBufferIndex, &gsmAttempt, 1);
    GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand4, &gsmBufferIndex, &gsmAttempt, 1);
    GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand5, &gsmBufferIndex, &gsmAttempt, 1);
    GSM_Send_Const_Command(gsmBuffer, buffer1, atResponse1, atCommand6, &gsmBufferIndex, &gsmAttempt, 1);

    InitTimer2_3();

    Delay_ms(2000);
    LCD_Cmd(_LCD_CLEAR);

    ADC1_Init();                   // Initialize ADC module
    Delay_ms(100);
    
    while(1) {

        moisture = (unsigned long)ADC1_Get_Sample(0) * 80 / 1023;
        Delay_ms(50);

        lightIntensity = (unsigned int)ADC1_Get_Sample(1);
        Delay_ms(50);

        if(!toggleDisplay) {
            LCD_Out(1,1,"Light: ");
            LCD_Out(2,1,"Moisture: ");
            IntToStr(lightIntensity, text);
            Ltrim(str);
            Rtrim(str);
            LCD_Out(1,13,text);
            memset(text, '\0', sizeof(text));
            strcat(text, "Light Intensity: ");
            IntToStr(lightIntensity, msg);
            Ltrim(msg);
            Rtrim(msg);
            strcat(text, msg);
            strcat(text, "\r\n");
            UART2_Write_Text(text);
        }

        if(!toggleDisplay) {
            LongToStr(moisture, text);
            Ltrim(text);
            Rtrim(text);
            strcat(text, "%");
            LCD_Out(2,13,text);
            strcat(text, " %\r\n");
            UART2_Write_Text(text);
        }

        DHT11_Start();
        DHT11_Read();

        //if(DHT11_Checksum == ((DHT11_Temperature >> 8) + (DHT11_Humidity >> 8) + (DHT11_Temperature & 0xFF) + (DHT11_Humidity & 0xFF))) {

            if(toggleDisplay) {
                LCD_Out(3,1,"Temperature:");
                LCD_Out(4,1,"Humidity: ");

                ByteToStr((DHT11_Temperature >> 8), text);
                Ltrim(text);
                Rtrim(text);
                LCD_Out(3,13,text);
                CustomChar(3,16);
                LCD_Out(3,17,"C");
                strcat(text, " degree C\r\n");
                UART2_Write_Text(text);

                ByteToStr((DHT11_Humidity >> 8), text);
                Ltrim(text);
                Rtrim(text);
                strcat(text, "%");
                LCD_Out(4,13,text);
                strcat(text, " %\r\n");
                UART2_Write_Text(text);
            }
        //}

        if((((DHT11_Humidity >> 8) > 85) || (moisture  > 60)) && executeOnce1 == 0) {
              Humidity_Pump = OFF;
              CopyConst2Ram(sms, msg6);
              Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

              executeOnce1 = 1;
        }
        else if((((DHT11_Humidity >> 8) < 30) || (moisture  < 30)) && executeOnce1 == 1) {
              Humidity_Pump = ON;
              CopyConst2Ram(sms, msg5);
              Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

              executeOnce1 = 0;
        }

        if(((DHT11_Temperature >> 8) > 30) && executeOnce2 == 0) {
             CopyConst2Ram(sms, msg9);
             Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

             executeOnce2 = 1;
        }
        else if(((DHT11_Temperature >> 8) < 30) && executeOnce2 == 1) {
             executeOnce2 = 0;
        }

        if((moisture < 30) && executeOnce3 == 0) {
            Moisture_Pump = ON;
            CopyConst2Ram(sms, msg7);
            Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

            executeOnce3 = 1;
        }
        else if((moisture > 40) && executeOnce3 == 1) {
            Moisture_Pump = OFF;
            CopyConst2Ram(sms, msg8);
            Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

            executeOnce3 = 0;
        }

        if(((moisture > 30) && (moisture < 40)) && executeOnce4 == 0) {
            Moisture_Pump = ON;
            CopyConst2Ram(sms, msg7);
            Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

            executeOnce4 = 1;
        }
        else if((moisture < 40) && executeOnce4 == 1) {
            Moisture_Pump = OFF;
            CopyConst2Ram(sms, msg8);
            Send_SMS(gsmBuffer, buffer1, atResponse1, atResponse4, atCommand1, atCommand5, atCommand9, sms, &gsmBufferIndex, &gsmAttempt, 1);

            executeOnce4 = 0;
        }
    }

- - - Updated - - -

Compiler is mikroC, is it a problem of UART initialization code?

- - - Updated - - -

Since I am using two UARTs, this portion is correct\?


Code:
 UART2_Init(9600); // Initialize Soft UART at 14400 bps
    Delay_ms(200);

    UART1_Init(9600);
    Delay_ms(200);

    DHT11_Init();
    
    U1IP0_bit = 0;                     // Set UART2 interrupt
    U1IP1_bit = 1;                     // Set interrupt priorities
    U1IP2_bit = 1;                     // Set UART2 interrupt to level 6

    U1RXIE_bit = 1;

    EnableInterrupts();
              
    U1RXIF_bit = 0;
 

Which device are you using?
Just by the look of it and until I know which data sheet to look at, you say in your comments that you are setting the UART2 interrupt etc. but I would expect the "U1IP0_bit" reference to be for UART1. Should you also be adding similar code for UART2?
Susan
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
I am using pic32mx795f512H

First UART is connected to sim900A, it is initializing
second directly to serial port of PC

since the second UART. uart2 to pc serial port the interrrupt priorities are needed?
 

If you have enabled UART2 interrupts, where is the Interrupt Service Routine (ISR) to handle UART2?


BigDog
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Thank you bigdogguru it was right
and I am having difficulty in setting in registers, so I have made one UART polling and another interrupt based
 

First UART is connected to sim900A, it is initializing
second directly to serial port of PC

You should determine exacly where lies the problem.
A good measure in that cases is echoing some byte locally through a loop-back connector.

When you said that the UART is connected "directly to serial port of PC" it is assumed you are doing that by some RS-232 converter.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top