2

I am using sim 800l with arduino. I am successfully sending AT command from arduino, not in serial monitor but I am unable to catch the response after each successful command execution if its ok or not. I want to do that because, if there is an error in a certain command the next command will not be executed unless its successful. Can you tell me is there any way to do so?

2
0

for a polling serial read I use this method :

bool tSim8_sendCommand(uint8_t sim_cmd[])
{
    uint8_t simOK[2] = {0}, i=20;
    tSoftSerial1_write(sim_cmd);
    tSoftSerial1_write("\r\n");
    while (i--)
    {
        simOK[0] = simOK[1];
        simOK[1] = tSoftSerial1_readChar();
        if(simOK[0] == 'O' || simOK[1] =='K')
        {
            return true;
        }
    }
    return false;
}

the variable i i the while loop, is used just for retries, so the program doesn't get trapped in an infinite loop. the code is self-explanatory. the incoming characters are "pushed" into an array till the array reads "OK".

for a non-blocking one, it's a bit complicated as you have to define state-machines and concurret loops. here is a method I use for finding out if the last transmission was OK:

void tsim_phase_ok_routine(uint8_t inChar)
{
    if(tsim_aux_buff[0] == 'O' && tsim_aux_buff[1] =='K' && tsim_aux_buff[2] =='\r')    
    {
        tsim_status_flag |= (1<<PHASE_OK);
        tsim_status_flag &=~(1<<PHASE_CON_ERR);
        return;
    }
    else    
    {
        tsim_aux_buff[0] = tsim_aux_buff[1];
        tsim_aux_buff[1] = tsim_aux_buff[2];
        tsim_aux_buff[2] = inChar;
        err_timeout--;
    }
    if(!(tsim_status_flag & (1<<PHASE_OK)) && !err_timeout)
    {
        tsim_status_flag &=~(1<<PHASE_OK);
        tsim_status_flag |= (1<<PHASE_CON_ERR);
    }
    
}

I define "PHASES" to find out which phase is sim800 in. the whole function would be written in RX interrupt service routine and the input character would be fed to it.

6
  • what is tSoftSerial1_readChar? – Juraj Nov 22 '20 at 17:35
  • @Juraj it was a software serial handler for reading chars – Tirdad Sadri Nejad Nov 22 '20 at 19:05
  • do you know the readBytesUntil functions? arduino.cc/reference/en/language/functions/communication/stream/… – Juraj Nov 22 '20 at 19:29
  • 1
    @Juraj actually, the code I wrote is in C99 so I could use it on any platform. I the link, yes it does the same job – Tirdad Sadri Nejad Nov 22 '20 at 19:51
  • 1
    @Juraj it's an answer anyway. that's why many question here have multiple answers. there would be people who just google the same question and may or may not be newbie or using the exact platform. and my answer is pure C so it can be used on arduino "as is" and many other platforms. we can't also deduce the OP is newbie because he wasn't aware of the method. – Tirdad Sadri Nejad Nov 22 '20 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.