Problem receiving sim800 sms data


#1

Hello!

Please friends, I really need your help, I already spent thousands of dollars in SMS :lol: :lol: :lol: and I could not figure out the problem :frowning: :frowning: :frowning: .

I’m making a simple program that should get a message, return via SMS and enter the LED blink loop.

As I do not need to know date, time and telephone number, I put a data start identifier for me which is the letter “Z”.

After receiving Z saved another 3 characters in the Buffer variable, send via SMS and try to compare to know if the data is correct, if they are entering the infinite loop

The problem is that the data that the buffer data [3] and [4] always get wrong.

I send Zmfa

I get OkZmf and 2 characters that are usually wrong

I’m using pic16f873A, 16Mhz crystal, MickorC compiler.


#2

Code:

char buffer[64];
char i;
char data_rx;
char control;
char mensage;


//================== interrupt ==============================================

void interrupt(){

//porta.f0 =~ porta.f0;

if (PIR1.RCIF) {

//porta.f0 =~ porta.f0;


//data_rx = RCREG;
data_rx = UART1_Read();
//buffer[i] = data_rx;
//i++;

if (( data_rx == 'Z') && (mensage == 0)){
//porta.f0 = 0; delay_ms(1000);
mensage = 1;
control = 1;
}

if(mensage == 1){
//control ++;

switch (control){
case 1 : buffer[1] = data_rx; 
// porta.f0 = 0;
//delay_ms(1000);
control = 2; 
break;

case 2 : buffer[2] = data_rx;
//porta.f0 = 0;
//delay_ms(1000);
control = 3;
break;

case 3 : buffer[3] = data_rx;
porta.f0 = 0;
delay_ms(1000);
control = 4;
break;

case 4 : buffer[4] = data_rx;
porta.f0 = 0;
delay_ms(1000);
control = 5;
break;
}

}
}


PIR1.RCIF = 0;
}

//=============================================================================

//========================== inicilize SIM800l ================================

void inicialize_sim(){

uart1_write_text("AT+CMGF=1"); //Configuramos o módulo para trabalhar com os SMS em modo texto
uart1_write (10);
uart1_write (13);
delay_ms(1000); //Pausa de 1 segundo
uart1_write_text("AT+CNMI=1,2,0,0,0"); //Configuramos o módulo para que nos mostre os SMS recebidos por comunicação serie
uart1_write (10);
uart1_write (13);


}
//=============================================================================

//======================== SEND SMS ===========================================

void send_sms(){

porta.f0 = 1;
delay_ms(1000);

porta.f0 = 0;
delay_ms(100);

porta.f0 = 1;
delay_ms(100);

porta.f0 = 0;
delay_ms(100);


porta.f0 = 1;
delay_ms(100);

delay_ms(3000);
UART1_Write_text("AT+CMGS=");

UART1_Write( 34 );

UART1_Write_text( "999061955") ;

UART1_Write( 34 );

UART1_Write( 13 );
delay_ms(200);

UART1_Write_text( "ok") ;
uart1_write (buffer[1]);
uart1_write (buffer[2]);
uart1_write (buffer[3]);
uart1_write (buffer[4]);

UART1_Write( 13 );
UART1_Write( 26 );
UART1_Write( 13 );

delay_ms(2000);


}
//=============================================================================


void main(){

trisa.f0 = 0; //led pin

porta.f0 = 0;

adcon1 = 0x06;

UART1_Init(9600); // Initialize UART module at 9600 bps

Delay_ms(15000); // Wait for sim800 to stabilize

inicialize_sim();

Delay_ms(5000); // Wait for sim800 to stabilize



PIR1.RCIF = 0; // Limpa Flag da interrupção de recebimento serial
PIE1.RCIE = 1; // Habilita interrupção de recebimento serial
//PIR1.RCIP = 1; // Seta interrupção de alta prioridade do recebimento serial

//RCON.IPEN = 1; // Seleciona o modo de 2 niveis de interrupção
INTCON.GIE = 1; // Habilita as interrupções de alta prioridade
INTCON.PEIE = 1; // Habilita as interrupções de baixa prioridade


i = 0;
mensage = 0;
control = 0;

//porta.f0 = 1;
//delay_ms(2000);


do{


porta.f0 = 1;


if(control == 5 ){
INTCON.GIE = 0;
send_sms();
control = 0;
mensage = 0;
INTCON.GIE = 1;
}



if ((buffer[1] == 'Z') && (buffer[2] == 'm') && (buffer[3] == 'f') && (buffer[4] == 'a')){
INTCON.GIE = 0;
do{
porta.f0 =~ porta.f0;
delay_ms(1000);
}while(1);
}


}while(1);

}

#3

I think you just have indexing problem.
May be you should ignore the first two indexes and save the remaining.


#4

Thanks for the answer, I’ll try to do this.