CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sim800c
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
NAVID



Joined: 14 Jun 2017
Posts: 28

View user's profile Send private message Send e-mail

sim800c
PostPosted: Mon Nov 26, 2018 8:26 am     Reply with quote

Hello everyone I have a problem with communicates sim800c. I use pic16f877a and i can send commands to sim800 and it works correctly but i can't display its answer...
This is my code. I hope somebody can help me.
tnx
Code:

#include <16F877A.h>
#device ADC=10
#use delay(crystal=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_c6,rcv=PIN_c7,bits=8,stream=PORT1,timeout=150)

char a[16];

#INT_RDA
void  RDA_isr(void)
{
for(i=0;i<=15;i++){
a[i]=getc();
}
flag=1;}



 if(flag==1){
  lcd_clear();
   flag=0;
   lcd_gotoxy(1,1);
   printf(lcd_putc,"%s              ",a);
   i=0;
   }

I just send important part of the code.
I need to say that when i send strings from my computer to pic its work good but in receiving strings from sim800 i have a problem!!


Last edited by NAVID on Mon Nov 26, 2018 10:39 am; edited 4 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 26, 2018 8:35 am     Reply with quote

Your approach is fundamentally flawed.

INT_RDA, means _one_ character is available to be read. Just one.
Not 32.

Then you don't show anything that would be making the SIM800 send you a reply. Presumably you are sending a command to do this?.

Then you are looking for 'o'. Why?. SIM800 replies will normally end in
'OK<CR>', but this is a capital 'O', not a lower case 'o', and you still have
two more characters needing to be received after this.

Then you don't show how 'a' is declared. If this is expecting to hold
32characters, it needs to be 33 characters long. If you expect your received
data to terminate when the 'o' is received, then the ISR needs to be adding
a NULL after this into this buffer.
The loop really should be terminated when this happens, or the ISR will sit
waiting for characters that don't arrive. Timeout will not result in the ISR
being re-triggered, so it will effectively be hung.

The receive code needs to be in the 'main' path not the ISR, or the string
needs to be built using a state machine, not a for loop.
NAVID



Joined: 14 Jun 2017
Posts: 28

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 26, 2018 10:37 am     Reply with quote

Ttelmah wrote:
Your approach is fundamentally flawed.

:D

Ttelmah wrote:
INT_RDA, means _one_ character is available to be read. Just one.
Not 32.

so what i must to do??!! its my receiver interrupt...


Ttelmah wrote:
Then you are looking for 'o'. Why?. SIM800 replies will normally end in
'OK<CR>', but this is a capital 'O', not a lower case 'o', and you still have
two more characters needing to be received after this.

oh sry, i just change the code for a test and forgot to fix it again ...

Ttelmah wrote:
Then you don't show how 'a' is declared. If this is expecting to hold
32characters, it needs to be 33 characters long. If you expect your received
data to terminate when the 'o' is received, then the ISR needs to be adding
a NULL after this into this buffer.


char a[16];
can you please explain more about "adding
a NULL..."?? i cant get it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 26, 2018 11:23 am     Reply with quote

OK.

Look at ex_sisr.c

This is the CCS example for a receive interrupt. Creates a 'circular buffer'
to hold the characters. You main code can then test if anything is available
with 'bkbhit'.

Your 'a' delcaration is a big problem since you are looping for 32 characters...

IN C, a 'string' is an array of characters, with a terminating NULL (0)
character. So (as an example), if you decided to store up to line feed for
example in the buffer, then when you store that, you put 0 into the next
location in the buffer, so string operations can then work. Without this the
printf for example, will keep printing other stuff from memory until a 0 is
hit.
If you wanted to store a 32 character 'string', the array would therefore
need to be 33 characters long...
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 26, 2018 11:42 am     Reply with quote

I have to ask a basic hardware question.
Is the 'sim800c' designed to operate at 5 volts? The 877 is a 5 volt PIC so if the sim800c is a 3 volt device, it cannot interface or work properly.
You should post a 'link' to what 'sim800c' device you have.
No amount of software changes can fix faulty hardware !

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Nov 26, 2018 11:57 am     Reply with quote

Fortunately, if he is using one of the standard shields designed for the Arduino, these have got FET level shifters built in, If he is not using a circuit like this, then there will be problems.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: sim800c
PostPosted: Mon Nov 26, 2018 12:50 pm     Reply with quote

NAVID wrote:

#INT_RDA
void RDA_isr(void)
{
for(i=0;i<=15;i++){
a[i]=getc();
}
flag=1;}


NAVID, you were told back in August 2017 not to do this.
You were told to only get one byte per interrupt, and not
to use a for() loop to get multiple bytes inside the RDA interrupt.
See the posts by ezflyr and Ttelmah:
http://www.ccsinfo.com/forum/viewtopic.php?t=56573
Why are you still doing this a year later ?
NAVID



Joined: 14 Jun 2017
Posts: 28

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 28, 2018 7:47 am     Reply with quote

temtronic wrote:
I have to ask a basic hardware question.
Is the 'sim800c' designed to operate at 5 volts? The 877 is a 5 volt PIC so if the sim800c is a 3 volt device, it cannot interface or work properly.
You should post a 'link' to what 'sim800c' device you have.
No amount of software changes can fix faulty hardware !

Jay


hi.i use this module:
http://roboeq.ir/products/detail/%D9%85%D8%A7%DA%98%D9%88%D9%84%20%D8%B1%D8%A7%D9%87%20%D8%A7%D9%86%D8%AF%D8%A7%D8%B2%20SIM800C/

i ask them can connect it directly to 5 volt micro and they say yes
NAVID



Joined: 14 Jun 2017
Posts: 28

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 28, 2018 7:53 am     Reply with quote

Ttelmah wrote:
Fortunately, if he is using one of the standard shields designed for the Arduino, these have got FET level shifters built in, If he is not using a circuit like this, then there will be problems.


hi.i fix it but i have new problem!! ((:
for example we i send a sms to sim800 i have some usless characters...
like this:
+CMT: "+989375091182","","18/11/28,17:21:07+14"
Hello
i just need "hello",how i can delete them and just use the sms??
NAVID



Joined: 14 Jun 2017
Posts: 28

View user's profile Send private message Send e-mail

Re: sim800c
PostPosted: Wed Nov 28, 2018 8:00 am     Reply with quote

PCM programmer wrote:
NAVID wrote:

#INT_RDA
void RDA_isr(void)
{
for(i=0;i<=15;i++){
a[i]=getc();
}
flag=1;}


NAVID, you were told back in August 2017 not to do this.
You were told to only get one byte per interrupt, and not
to use a for() loop to get multiple bytes inside the RDA interrupt.
See the posts by ezflyr and Ttelmah:
http://www.ccsinfo.com/forum/viewtopic.php?t=56573
Why are you still doing this a year later ?


wow O-o
how u can remember?!?!
im noob at programming.so what i can do?
ex_sisr.c is enough ??
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 28, 2018 9:23 am     Reply with quote

There are also a few posts on this board about using the RECEIVE_BUFFER option in #use rs232

example:
#USE RS232(BAUD=115200, UART3, BITS=8, PARITY=N, STOP=1, STREAM=PC, ERRORS, RECEIVE_BUFFER=128)

It automatically sets up the RDA interrupt for you and puts characters into a circular buffer of the size you specify in RECEIVE_BUFFER. Then, you can just use kbhit() in your while loop to check if there are new characters in your buffer. Then you can use gets() or getc() to take characters out of the buffer without having to worry about staying inside an interrupt too long. Read the manual to see the differences between the flavours of gets() and getc() and their specific functions.
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 28, 2018 10:40 am     Reply with quote

and...
while your project is open, pressing F11 will open the CCS manual !!
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Wed Nov 28, 2018 11:24 am     Reply with quote

NAVID wrote:
Ttelmah wrote:
Fortunately, if he is using one of the standard shields designed for the Arduino, these have got FET level shifters built in, If he is not using a circuit like this, then there will be problems.


hi.i fix it but i have new problem!! ((:
for example we i send a sms to sim800 i have some usless characters...
like this:
+CMT: "+989375091182","","18/11/28,17:21:07+14"
Hello
i just need "hello",how i can delete them and just use the sms??


The first line gives who the number the SMS comes from and the time.
Then there is a line feed.
The the SMS itself followed by another line feed.
So just have your code throw away the incoming characters till it sees the
line feed, then start storing characters till the next line feed.
NAVID



Joined: 14 Jun 2017
Posts: 28

View user's profile Send private message Send e-mail

PostPosted: Sat Dec 01, 2018 8:53 am     Reply with quote

dluu13 wrote:
There are also a few posts on this board about using the RECEIVE_BUFFER option in #use rs232

example:
#USE RS232(BAUD=115200, UART3, BITS=8, PARITY=N, STOP=1, STREAM=PC, ERRORS, RECEIVE_BUFFER=128)

It automatically sets up the RDA interrupt for you and puts characters into a circular buffer of the size you specify in RECEIVE_BUFFER. Then, you can just use kbhit() in your while loop to check if there are new characters in your buffer. Then you can use gets() or getc() to take characters out of the buffer without having to worry about staying inside an interrupt too long. Read the manual to see the differences between the flavours of gets() and getc() and their specific functions.


hi,i have some few questions...
i must define new char variable named RECEIVE_BUFFER[128]??
like this: char RECEIVE_BUFFER[128]; ??!
or just like you write it in option??so how i can use it??
can u show me an example??
i read the ccs help about rs232 but its example does not explain that...
and what is the bkhit(); ??where i can find and how can use it??
tnx
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Sat Dec 01, 2018 9:05 am     Reply with quote

You are right that unfortunately, the manual does not say much about this.

With the RECEIVE_BUFFER option, the circular buffer and the RDA interrupt for placing characters into the receive buffer are automatically generated. You don't need to declare the buffer, or write the ISR. So all you should need is something like this:

Code:
int main(void)
{
    char a;
    while(1)
    {
        if(kbhit())
        {
            a=getc();
            // do stuff with a. You could even put your loop here.
        }
    }
}


kbhit() evaluates as true if there are new characters in the buffer, and false if there are not.

The main point of this is to move the slow for loop out of the RDA interrupt because interrupt routines are meant to be fast.

Also, I just noticed you might not have found "bkhit()" because it is actually "kbhit()". It is in the manual along with the rest of the built-in functions.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group