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

fprintf and disable_interrupts(int_ext), please help...

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



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

fprintf and disable_interrupts(int_ext), please help...
PostPosted: Thu Jul 22, 2004 8:56 am     Reply with quote

Hello all,

#use rs232(baud=4800,xmit=MOut,rcv=MIn,stream=MODEM)

In several parts of my program I have the following code, with different strings sent to the MODEM:

disable_interrupts(int_ext);
fprintf(MODEM,"AT#CONNECTIONSTART\r");
enable_interrupts(int_ext);

I have 3 questions, please help me out:

1) If I remove the disable/enable interrupts instructions, it does not work (I can not talk or receive the modem), why is that?

2) how can i convert the above code into a function in which I pass the string I want to send as a parameter?

3) is it ok to use fprintf?, I've read it's best to use fputc in a loop but I don't know how...I'm using STREAMS, have a modem, GPS and PC...


Thank you in advance
Peter
Ttlmah
Guest







Re: fprintf and disable_interrupts(int_ext), please help...
PostPosted: Thu Jul 22, 2004 9:14 am     Reply with quote

runtime wrote:
Hello all,

#use rs232(baud=4800,xmit=MOut,rcv=MIn,stream=MODEM)

In several parts of my program I have the following code, with different strings sent to the MODEM:

disable_interrupts(int_ext);
fprintf(MODEM,"AT#CONNECTIONSTART\r");
enable_interrupts(int_ext);

I have 3 questions, please help me out:

1) If I remove the disable/enable interrupts instructions, it does not work (I can not talk or receive the modem), why is that?

2) how can i convert the above code into a function in which I pass the string I want to send as a parameter?

3) is it ok to use fprintf?, I've read it's best to use fputc in a loop but I don't know how...I'm using STREAMS, have a modem, GPS and PC...


Thank you in advance
Peter

You don't tell us whether there is a hardware, or software UART, on this stream?.
I'd guess it is a software UART. If so, then this explains the interrupt problem. The problem here is that the sgftware UART is totally dependant on accurate software timings. Unfortunately, and interrupt will itself introduce a time error, and the comms will stop working.
The alternative that I'd consider is something like this:
Code:

void intoffputc(int8 val) {
    disable_interrupts(INT_EXT);
    fputc(val,INT_EXT);
    enable_interrupts(INT_EXT);
}


Now this will take a single character, disable the interrupts, send this character, and then re-enable the interrupts. For your example string, you can then use:

intoffputc("AT#CONNECTIONSTART\r");

This uses the CCS 'shortcut', which for a constant string, will call a function expecting to receive an integer, character at a time, for each character in the string. The advantage, is that the interrupts will only be disabled for one character time, instead of for the length of the whole string.
The same routine can be used if you need formatted output, with printf, using syntax like:

printf(intoffputc,"sending a number %d\n",num);

Best Wishes
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

PostPosted: Thu Jul 22, 2004 9:28 am     Reply with quote

Hello Ttlmah,

Thank you for your response, in your code:

fputc(val,INT_EXT); wouldn't that be fputc(val, MODEM)?

Thank you
Ttelmah
Guest







PostPosted: Thu Jul 22, 2004 10:17 am     Reply with quote

runtime wrote:
Hello Ttlmah,

Thank you for your response, in your code:

fputc(val,INT_EXT); wouldn't that be fputc(val, MODEM)?

Thank you

Yes.
As you can tell, the code was 'off the cuff', and I just slipped on the name of the tream (in a rather silly way). I was using 'INT_EXT', in the line before and after...
For my 'next trick', I'll try 'disable_interrupts(MODEM)'...
:-)

Best Wishes
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