View previous topic :: View next topic |
Author |
Message |
guest453 Guest
|
3.3 v logic or 5 v logic |
Posted: Tue Apr 07, 2009 12:49 am |
|
|
Hi all, i have the following code;
Code: | #include <24FJ16GA002.h>
#include <string.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICS3 //ICD communication channel 3
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FRC //Internal Fast RC Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is general purpose output
//#FUSES NOPR //Primary oscillaotr disabled
#use delay(clock=4000000)
#pin_select U1TX=PIN_B3 //RS-232 TX PIN 21
#pin_select U1RX=PIN_B2 //RS-232 RX PIN 22
#use rs232(UART1,baud=19200,parity=N,bits=8, STREAM=PC,ERRORS)
void main()
{
char c;
fprintf(PC,"ready");
output_high(PIN_B7);
output_high(PIN_A0);
while(1){
if(kbhit(PC)){
c=getc(PC);
putc(c,PC);}
}
} |
I am just trying to send a character to the hyperterminal.I am using pic24fj16ga002 and max232 cpe to transmit the characters to the pc.But the problem is when i press w it displays the correct character but when i press a it displays q also when i press c it displays s!!!!When i looked at ascii character table i saw that a is 61 Hx and q is 71 Hx,c is 63 Hx and s is 73 Hx and the problem is the same for other ascii characters.
a=0110 0001
q=0111 0001
when i press q it displays it but i dont know why the 5.th bit goes 1 instead of 0 when i press a (or the others)
Does anyone can help me ?
Thanks. |
|
|
ccesaretto
Joined: 03 Mar 2009 Posts: 5
|
|
Posted: Tue Apr 07, 2009 3:35 am |
|
|
I had similar issues with the serial port. I resolved using an external oscillator rather than the internal one. |
|
|
Guest
|
|
Posted: Tue Apr 07, 2009 4:42 am |
|
|
Please have a look into the datasheet if the internal oscillator meets the requirements of max. 2% speed deviation at the serial port or not. Some combinations of clock and desired baudrate will not match. To figure out if you have a sampling/baudrate problem or not try other baudrates. |
|
|
guest453 Guest
|
3.3 v logic or 5 v logic |
Posted: Tue Apr 07, 2009 3:24 pm |
|
|
Thanks guys,
Now it works. |
|
|
bsturm
Joined: 23 Feb 2009 Posts: 29
|
|
Posted: Tue Apr 07, 2009 4:47 pm |
|
|
What did you change? Did you have to add an oscillator? |
|
|
guest453 Guest
|
|
Posted: Tue Apr 07, 2009 8:04 pm |
|
|
i disabled internal oscillator and enabled external and put an external oscillator.It worked. |
|
|
bsturm
Joined: 23 Feb 2009 Posts: 29
|
|
Posted: Tue Apr 07, 2009 8:31 pm |
|
|
I suspected that is what you had to do. I have had the same problem and I haven't fixed it yet. The internal oscillator seems to hold time very well, well within 1% when I measured it. But I still couldn't communicate with Hyperterminal or a serial LCD. I could communicate with my PicKit2 in serial mode no problem.
I captured my bits on a scope and the timing looked excellent, but still not working with Hyperterminal. I don't understand why it wouldn't work. I even adjusted my clock speed up and down a little, but still nothing. I don't need async comms at the moment, so I gave up. I am using my osc pins as IO, so adding a resonator would be difficult. I'm glad that you got yours working. |
|
|
guest453 Guest
|
|
Posted: Wed Apr 08, 2009 1:17 am |
|
|
well i used the code that i posted.i set the baudrate 9600 and i used 4 mhz crystal.i read pcd manual and i changed the first line of fuses statement like this
#fuses HS, PR, NOWDT then
#use delay(clock=4000000) for clock.I think when i tried higher baudrate it didn't work but i am not sure.I must check it tomorrow.Do you see nothing in the hyperterminal?
i set hyperterminal like this:
baud:9600
parity:N
stop bits:1
hardware:N
did you set hyperterminal like that.by the way mine worked i didn't spend time for the internal oscillator anymore:)
I wonder if anyone has a sample code for pic24fj128ga106 using four hardware uarts.If anyone shares i will apreciate. |
|
|
bsturm
Joined: 23 Feb 2009 Posts: 29
|
|
Posted: Wed Apr 08, 2009 9:23 pm |
|
|
I was getting garbage characters on Hyperterminal, smiley faces and what not. Sometimes it would work properly for a short time. I did have it set to 9600-8-N-1. I also tried 2400, 1200,300 and even 110 baud with no luck. |
|
|
guest453 Guest
|
|
Posted: Thu Apr 09, 2009 8:02 pm |
|
|
Be sure about voltage levels. All must set to 3.3. Then be sure that your line transceiver is working(max232 ext.) Then use a simple code (echo a character) that works. If it doesn't work post your circuit and code:) |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Apr 10, 2009 7:23 am |
|
|
If it works sometimes and not others it sounds like the clock or the voltage is marginal. Try forcing a software UART and setting the baud rate 2% high or 2% low.
Run a test and show us what you expect and the hex or binary you get, not just "smiley face". _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
bsturm
Joined: 23 Feb 2009 Posts: 29
|
|
Posted: Fri Apr 10, 2009 9:26 am |
|
|
Thanks for the suggestions. For now, I have moved on to other issues, and I am not actively working it. Serial communication was just a convenience item, not necessary at this time. I was just curious what the original poster had found. I will start by checking voltage levels when I get back to it. |
|
|
|