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 support@ccsinfo.com

Read data without interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
norta



Joined: 19 Oct 2013
Posts: 4

View user's profile Send private message

Read data without interrupts
PostPosted: Sat Oct 19, 2013 3:17 pm     Reply with quote

Hello Shocked

I tried for some time to communicate with a GSM modem but I can not run my program correctly

Can you help me?
The goal is to run the program without using interrupts

Code:

Code is not OK, see this link :
http://www.ccsinfo.com/forum/viewtopic.php?t=50390&highlight=sms



Last edited by norta on Tue Oct 22, 2013 2:17 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 19, 2013 5:29 pm     Reply with quote

Quote:
char myok[2] = "OK";

That's wrong. String arrays require space for the string terminator byte.
So you really need to set the array size to 3. Or, leave it blank and let
the compiler set it to 3 automatically.
norta



Joined: 19 Oct 2013
Posts: 4

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 6:28 am     Reply with quote

Hi PCM programmer,

Thanks for your reply ! Laughing it is good

Do you have any comments for this function ?
It is the best way ?

Good day
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 12:17 pm     Reply with quote

Simple answer. No.

Big problem is the long delay. If anything arrives on the serial, while this is going on, it'll be lost.

I have to ask 'why' you don't want interrupts?. Even f you don't want to use serial interrupts, consider having a 'heartbeat' interrupt, and do your delays by waiting for this. This way you can poll the serial regularly while waiting.

However if you 'insist' on doing things the hard way, then the same effect can be done by reading a timer.

Forcing yourself to do without interrupts, is a bit like trying to drive a car, and then saying "I don't want to use the steering wheel"....

Best Wishes
norta



Joined: 19 Oct 2013
Posts: 4

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 1:06 pm     Reply with quote

Hello,

Thank you for your answer!

I will not use the interrupt for one simple reason, I'll try to explain:
I need to read a long SMS PDU mode, the size of the SMS PDU is greater at the maximum possible size for buffeur reception in this case I do not see another way to read the message
The idea is to read the response from the modem and then ignore the data not useful ....

Here is my code but not functional
Can you help me?

Code:


Code is not OK, see this link :
http://www.ccsinfo.com/forum/viewtopic.php?t=50390&highlight=sms



Last edited by norta on Tue Oct 22, 2013 2:18 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Mon Oct 21, 2013 12:44 am     Reply with quote

Right.

The first thing is to change how you are thinking.

Using interrupts, would not imply having a buffer the size of the message. The 'point' about buffering with interrupts is to allow a little extra time to do things, when you have slow functions. EX_SISR, shows how to use interrupt driven serial receive, to give this time. It has a couple of faults that have been discussed here many times, but as shown, works.

Imagine (for example), that you are parsing a message from a GPS. As the characters arrive, you work out where you are in the message (probably a counter), and when you get to the characters you want, you read these and convert them to a numeric format inside the PIC. Now, counting the characters and rejecting them, takes just a few uSec/character. However when you get to the numeric 'part', you have to read the digit, subtract '0' to convert it from ASCII to numeric, add it to the value so far retrieved, and multiply this by ten. Generally numbers like this will be floating point, or large scaled integers, and this can take significant time. When you realise that a singe fp multiplication, takes nearly 200uSec (at your clock rate), and also accessing characters in an array, also takes several uSec, it doesn't take much being done, for the code to not be able to 'keep up' with the incoming characters....

Generally such periods will be short.
So (for instance), after falling behind by several uSec in decoding the longitude (say), you then have a simple comma, in the GPS data which allows you to catch up a lot.

The point about using interrupts, is to allow some 'elasticity' between the code, and the receipt. As standard, you have just one character time, from the moment a character arrives, till the next one has to be handled. Using polling, if a character is missed, it is gone. There is a 'grand total' of under two characters of buffering in the hardware...

Similarly using a timer 'tick', rather than using delays. If (for instance), you want to wait a number of seconds before sending a new message request, you can just load a counter, which is decremented in an interrupt. Then loop _doing other things_ until the counter gets to zero. If instead you use 'delay', the processor effectively stops doing anything till the time has passed.

Using interrupts effectively allows you to separate doing 'operations', from the 'moment' when they have to happen, and massively increases what the processor can appear to be able to do.

Then do a search for 'state machine'.

What you want to do, would classically be handled by interrupt driven serial communication, combined with a state machine determining what is to be done with each received character.

As a further comment, we are back to PCM programmers comment about the size of arrays.

You allocate char temp[] = "";

This means that 'temp' is a pointer into memory, pointing to an allocated area able to hold just one character.

Then you start pumping eighteen characters into this area. No wonder it doesn't work....

Best Wishes
norta



Joined: 19 Oct 2013
Posts: 4

View user's profile Send private message

PostPosted: Tue Oct 22, 2013 2:13 pm     Reply with quote

Thank you for your answer is really helpful ...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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