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

Does printf inhibit gets?

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



Joined: 24 Oct 2013
Posts: 13

View user's profile Send private message

Does printf inhibit gets?
PostPosted: Sat May 09, 2015 5:02 am     Reply with quote

Hi,
I am trying to control one output through ESP8266. First I am initializing the ESP module, it works fine but if I send "be" string to the PIC (from android device through ESP), the output doesn't go to high state. I recognized if I delete the init(); statement and compile again the program and write to the PIC, the string handling works and the output go to high state.
But if I switch off the power supply I should play again this "game".
Code:
#include<18f25k20.h>
#include<string.h>

#fuses nowdt,intrc_io,put,noprotect,nobrownout,
#use delay(clock=16Mhz)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,bits=8,parity=N,stop=1)

char string[30];

void init (){

printf("AT+CWMODE=3\xD\xA");
delay_ms(1500);
printf("AT+CWJAP=\x22WIFI\x22,\x22PASS\x22\xD\xA");
delay_ms(5500);
printf("AT+CIPMUX=1\xD\xA");
delay_ms(1500);
printf("AT+CIPSERVER=1,1336\xD\xA");

}

void main (){

init();

while(true){

gets(string);

if ((string[10]=='b')&&(string[11]=='e')){
output_high(pin_b0);
}
if ((string[10]=='k')&&(string[11]=='i')){
output_low(pin_b0);
}
}
}
temtronic



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

View user's profile Send private message

PostPosted: Sat May 09, 2015 5:26 am     Reply with quote

Have a look at the CCS example ex_sisr.c. It's an ISR driven circular buffer. With any(all) serial communications you _need_ to have some form of buffering of the data coming into the PIC's UART. It only has a 2-3 char 'buffer' and will overrun aka 'stall', 'lockup', 'crash' when the 4th char arrives.
You also need to add 'errors' to the uses RS232(...options...) as that adds some code to prevent this 'overrun' error.


jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat May 09, 2015 10:26 am     Reply with quote

also in the CCS library INPUT.C
look at
get_string()

which i successfully modified using an
addition of kbhit() and a timer rollover
to make sure that the function would not hang in an endless loop
if no <CR> was forthcoming. see the library for yourself:
is not hard to make the change i mention.........

gets() is a dangerous and IMHO pretty useless function
in terms of the risk to program reliability it represents.

Best used in Proteus but NOT in the real world !!
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