View previous topic :: View next topic |
Author |
Message |
hanhao
Joined: 21 Mar 2007 Posts: 24
|
problem with printf using PIC16F687 - garbage on RS232 |
Posted: Sun Mar 25, 2007 7:04 pm |
|
|
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
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
|
|
Posted: Sun Mar 25, 2007 7:16 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 7:46 pm |
|
|
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
|
|
|
hanhao
Joined: 21 Mar 2007 Posts: 24
|
|
Posted: Sun Mar 25, 2007 8:12 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 8:23 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 8:29 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 8:37 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 8:51 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 8:59 pm |
|
|
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
|
|
Posted: Sun Mar 25, 2007 9:07 pm |
|
|
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?
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
|
|
|
hanhao
Joined: 21 Mar 2007 Posts: 24
|
|
|
hanhao
Joined: 21 Mar 2007 Posts: 24
|
|
|
hanhao
Joined: 21 Mar 2007 Posts: 24
|
|
Posted: Mon Mar 26, 2007 12:54 am |
|
|
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
|
|
|
|