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

supernatural problem with getc()

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



Joined: 16 Feb 2015
Posts: 2

View user's profile Send private message

supernatural problem with getc()
PostPosted: Mon Feb 16, 2015 1:09 am     Reply with quote

Ok i did a big code of interfacing GSM with pic 16f887. It worked fine except the sms receiving part. I found the error was with the receiving serial data and start debugging that alone using a small code and got cranky.

Code:

#include <16F887.h>
#device ADC=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                   
#use delay(internal=8MHz)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

void main()
{
//delay_ms(10);
printf("start");
//delay_ms(1000);
printf("end");
for(;;)
{
printf("%c",getchar());
}
}


OUTPUT - startend<echos the chars i type>

but when i uncomment the delay lines

OUTPUT - start<delay>end<doesnt echo>

But it works perfect in proteus. I send the data after the "end" is printed on my serial monitor.Pls help.


Last edited by r_karthik_r on Mon Feb 16, 2015 2:16 am; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Mon Feb 16, 2015 2:02 am     Reply with quote

Add the keyword 'ERRORS' to the RS232 declaration.

Repeat 50*. "When using the hardware UART, I must use 'ERRORS' or have my own error handling. Repeat must."

Problem is that if two characters of _anything_ are received during the delays, the UART hardware _will_ be hung, and will not recover without ERRORS.
r_karthik_r



Joined: 16 Feb 2015
Posts: 2

View user's profile Send private message

PostPosted: Mon Feb 16, 2015 2:15 am     Reply with quote

Ttelmah wrote:
Add the keyword 'ERRORS' to the RS232 declaration.

Repeat 50*. "When using the hardware UART, I must use 'ERRORS' or have my own error handling. Repeat must."

Problem is that if two characters of _anything_ are received during the delays, the UART hardware _will_ be hung, and will not recover without ERRORS.


bt I send the serial data after the end is printed only.
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Mon Feb 16, 2015 5:17 am     Reply with quote

Remember a 'real' chip waking up, often _will_ see garbage characters arrive. Without ERRORS these will hang the UART. Proteus does not have such 'real' behaviour.
temtronic



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

View user's profile Send private message

PostPosted: Mon Feb 16, 2015 6:04 am     Reply with quote

also....
it's real good practice to 'flush the UART buffer'(actually all buffers/variables) before 'main()' is executed. This will eliminate 100% of the 'random' data that does 'weird' things to your program.

Jay
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed Feb 18, 2015 4:25 am     Reply with quote

Ttelmah wrote:
Add the keyword 'ERRORS' to the RS232 declaration.

Repeat 50*. "When using the hardware UART, I must use 'ERRORS' or have my own error handling. Repeat must."

Problem is that if two characters of _anything_ are received during the delays, the UART hardware _will_ be hung, and will not recover without ERRORS.


Really, CCS should make ERRORS the default behaviour, and have "NOERRORS" for those who want to do their own handler..
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Wed Feb 18, 2015 11:54 am     Reply with quote

Agreed. Especially in the Wizard, so that people not understanding this will automatically get the safe behaviour.
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RE:
PostPosted: Mon Feb 23, 2015 10:44 pm     Reply with quote

The word supernatural in the header got me interested in this topic.

thanks
a
temtronic



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

View user's profile Send private message

PostPosted: Tue Feb 24, 2015 2:13 pm     Reply with quote

Well Proteus doesn't care about power supplies.....Are you running the PIC at 5 volts and the GSM at 3 volts ???

That alone will certainly cause 'issues'...

Jay
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