I have the below program, in which data is not coming to second UART,
first uart is working,
someone kindly help me
Is the second UART initliaization correct?
first uart is working,
someone kindly help me
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;
}
}
}
Is the second UART initliaization 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;