View previous topic :: View next topic |
Author |
Message |
r_karthik_r
Joined: 16 Feb 2015 Posts: 2
|
supernatural problem with getc() |
Posted: Mon Feb 16, 2015 1:09 am |
|
|
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: 19546
|
|
Posted: Mon Feb 16, 2015 2:02 am |
|
|
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
|
|
Posted: Mon Feb 16, 2015 2:15 am |
|
|
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: 19546
|
|
Posted: Mon Feb 16, 2015 5:17 am |
|
|
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: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Feb 16, 2015 6:04 am |
|
|
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
|
|
Posted: Wed Feb 18, 2015 4:25 am |
|
|
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: 19546
|
|
Posted: Wed Feb 18, 2015 11:54 am |
|
|
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
|
RE: |
Posted: Mon Feb 23, 2015 10:44 pm |
|
|
The word supernatural in the header got me interested in this topic.
thanks
a |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue Feb 24, 2015 2:13 pm |
|
|
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 |
|
|
|