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

problem with printf using PIC16F687 - garbage on RS232
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

problem with printf using PIC16F687 - garbage on RS232
PostPosted: Sun Mar 25, 2007 7:04 pm     Reply with quote

problem with printf using PIC16F687 - garbage on RS232

here is my header
Code:


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES RC                       //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled

//#use delay(internal=8M)
#use delay(clock=2000000)
#use rs232(baud=19200,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8)



here is my printf command
Code:
printf("TESTING");


here is the settings i put on serial input/output monitor. This program comes as a tool on CCS C compiler


here is the garbage i got
note that the first few lines are different because the bytes are not inverted
i set inversion because i dont have a NOT gate or a MAX chip

the serial was connected to pin 10 port B7


can anyone tell me why i am getting garbage instead of "TESTING"?
and the solution to this problem
Mattr0



Joined: 27 Mar 2005
Posts: 30

View user's profile Send private message Visit poster's website

PostPosted: Sun Mar 25, 2007 7:16 pm     Reply with quote

Chances are you oscillator setting are incorrect. In fact in your header file you have selected RC with 20 mhz it should be HS

Code:

#FUSES RC                       //Resistor/Capacitor Osc with CLKOUT


try
Code:

#FUSES HS                     // High speed oscillator


HS must be used when the speed is great or than 4 Mhz.

[/quote]
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 7:46 pm     Reply with quote

thanks for your help
but it didnt work

again, the earlier part is for non inverted bytes and the 2nd portion is inverted


here is the result, seems to be the same...




i also changed the rate to 9600 and these are my results

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:08 pm     Reply with quote

What crystal, oscillator, resonator, or R-C circuit do you have connected
to the CLKIN and CLKOUT pins on the 16F687 ?

If you have a crystal, tell the value of the capacitors that you have
connected to it.


A crystal looks like this:
http://rocky.digikey.com/WebLib/ECS/Web%20Photos/HC-49US.jpg

An oscillator looks like this:
http://rocky.digikey.com/WebLib/CTS/Web%20photos/MXO45.jpg
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:12 pm     Reply with quote

currently no crystal connected to OSC1 and OSC2


they are floating pins

btw i am using CCSC compiler 4.013 and MPLAB IDE 7.5
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:23 pm     Reply with quote

Try this test program. Type characters into the terminal window.
See if the PIC sends them back to the PC. It should work.
This program uses the PIC's internal RC oscillator.
Code:

#include <16F687.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, BROWNOUT   
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)

//=======================================
void main()
{
int8 c;

while(1)
  {
   c = getc();
   putc(c);
  }

}
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:29 pm     Reply with quote

Using INTRC_IO oscillator type, does it need to configure the oscillator frequency using
setup_oscillator(OSC_8MHZ) ?
If it doesn´t defined, what´s the default osc freq ?

Humberto
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:37 pm     Reply with quote

If the #use delay() statement is placed below the #fuses statement,
the compiler will automatically setup the internal oscillator correctly.
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:51 pm     Reply with quote

PCM programmer wrote:
Try this test program. Type characters into the terminal window.
See if the PIC sends them back to the PC. It should work.
This program uses the PIC's internal RC oscillator.
Code:

#include <16F687.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, BROWNOUT   
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)

//=======================================
void main()
{
int8 c;

while(1)
  {
   c = getc();
   putc(c);
  }

}


here are the results when i type "qwerty" on my keyboard




inverted bytes, note that i typed "qwerty qwerty"



non inverted bytes, note that i type "qwertyuopasdfghjklzxcvbnm" in this case and hence the longer line

non inverted bytes actually makes more sense but still does not display the exact stuff i type


Last edited by hanhao on Sun Mar 25, 2007 9:01 pm; edited 1 time in total
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 8:59 pm     Reply with quote

hanhao,

Have you changed the baud rate from 19200 to 9600 in the serial monitor to match
the example code posted by PCM Programmer?
If it doesn´t fix, pls tell us your hardware arrangement.

Humberto
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 9:07 pm     Reply with quote

Humberto wrote:
hanhao,

Have you changed the baud rate from 19200 to 9600 in the serial monitor to match
the example code posted by PCM Programmer?
If it doesn´t fix, pls tell us your hardware arrangement.

Humberto


yes i did

here the configuration



i have an O scope with me, want me to probe anything? Laughing


Last edited by hanhao on Sun Mar 25, 2007 9:23 pm; edited 1 time in total
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 9:26 pm     Reply with quote

According to your drawing, it seems like you are connecting the PIC pins directly to
the DB9 connector, hence directly to RS232 levels, wich is wrong. PIC voltages
swing between 0 to 5VDC, RS232 levels swing between +12 to -12VDC.
You need to connect a level converter like MAX232 in between them.

http://www.ccsinfo.com/faq.php?page=pic_to_pc
http://www.ccsinfo.com/faq.php?page=rs232_errors

Humberto
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 9:48 pm     Reply with quote

i do not have a MAX232 chip
but i do have 2N7002k chips
can i use this configuration instead?

http://www.botkin.org/dale/rs232_interface.htm
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 10:52 pm     Reply with quote

i guess i need this connection

from http://www.lookrs232.com/rs232/level_converters.htm

OR THIS


from http://sodoityourself.com/max232-serial-level-converter/

will try out once the chip comes

i notice that the 2 schematics have different capacitor values
which value should i use? 10u or 1u?
hanhao



Joined: 21 Mar 2007
Posts: 24

View user's profile Send private message

PostPosted: Mon Mar 26, 2007 12:54 am     Reply with quote

opps, i cant find a MAX232 chip, but i do have a surface mount sipex SP3243 chip. i guess i'll use that in place of the MAX232

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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