Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

serial port interface help

Status
Not open for further replies.

david90

Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,610
Code:
#elif defined(__PCH__)
#include <18F458.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12
#endif


#byte port_b=6


void main() {
  
   printf("HiThere");

}
I get garbage output in hyperterminal. The baud rate was set to 9600, 8 bits, flow control non and no parity.

Is there anything wrong with my code? The c code above is for PIC C compiler/CCS C
 

philba

Full Member level 2
Joined
Jan 26, 2006
Messages
132
Helped
13
Reputation
26
Reaction score
1
Trophy points
1,298
Activity points
3,102
garbage usually means a baud rate mismatch. Did you change the baudrate in hyperterm? I believe there is a bug that requires that you restart hyperterm to get the baudrate change to take effect.

If that's not it, try switching baud rates.

I don't know CCS but is that for bit banged serial I/O?

By the way, I don't see a PIC18F458 listed on the microchip site.
 

Benny

Junior Member level 2
Joined
Dec 2, 2005
Messages
23
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,281
Activity points
1,552
Hi,

One more thing you should check is if the GND line is connected at you communication cable, i had this problem once and it solved the problem.

Ben.
 

hesho13

Junior Member level 1
Joined
Dec 31, 2004
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
167
check the crystal oscillator of your controller,crystal oscillator of your controller should be equal to that seen by your compiler.
 

david90

Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,610
my connection is good and my baud rate on the MCU agrees with hyperterminal.

I'm using an 8Mhz crystal but I don't know the cap values. I just connect it to the mcu without the caps. could that change the speed?
 

philba

Full Member level 2
Joined
Jan 26, 2006
Messages
132
Helped
13
Reputation
26
Reaction score
1
Trophy points
1,298
Activity points
3,102
yes, you will need caps. try 22 pf though anything bewteen 12 and 40 pf should work with some frequency error but probably not enough to screw up your baudrate. the crystal's datasheet should tell you what cpas to use. the crystal leads connect to osc1 and osc2 and then caps go from the osc1 to gnd and ocs2 to gnd.

you are using a an rs232 driver like a max232, right?
 

sp

Full Member level 6
Joined
Jan 1, 2004
Messages
396
Helped
23
Reputation
46
Reaction score
2
Trophy points
1,298
Location
Floating Garden
Activity points
4,046
try putc instead of the printf... printf is always buggy in CCS C...

anyway... i would suggest tht u use the interrupt method n use a button so u dont hav to press MCLR (for ur code) when u wanna check the msg from ur PIC...

use putc wth interrupt then when button pressed, send the msg to ur pc...

another prob mayb is tht when after the MCLR u press for ur msg to display the msg on ur pc... the pic might not stable yet... is it posible?

sp
 

david90

Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,610
I tried putc and it doesn't work. Anymore suggestion? I'm not using max232 but from what i've read it should work without problems.
 

AVM_NOIDA

Member level 1
Joined
Jan 31, 2006
Messages
39
Helped
7
Reputation
14
Reaction score
5
Trophy points
1,288
Location
Asia
Activity points
1,749
Hi

I have not done serial programming with PIC but I have connected a few different 8051 and AVR's to PC using serial . This is my experience.

If you fail at 9600 try connecting at the lowest baud rate that both Hyperterminal and PIC can support this will take care of minor mis-match in baud rate etc. Since you can see garbage it means your connections are correct.

what circuit are you using to replace max232 ? Once due to the requirement of opto-isolated circuit I had to design without max232 but I made sure that the signal levels were near +12 and -12 though without any extra power supply.
 

mmohamed15

Advanced Member level 4
Joined
Mar 23, 2005
Messages
112
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,296
Activity points
2,116
try the example codes from the pic list they have a lot of working codes examples in that website
 

david90

Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,610
I added "INVERT" to the #use RS232 and it worked. NO more garbage. I had to remove rcv=PIN_C7 though or else it won't compile. Why??

edit: problem solved. I used max232 and everything worked out. I don't get why sometime u don't have to use it. I guess it depends on the pc.
 

niket_304

Member level 4
Joined
Dec 21, 2005
Messages
73
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
2,002
may be u are facin the problem with <cr> or baudrate mismatch. try changing the baudrate. may be that will help u. else see to it that you get proper <cr> end of string. i have a vb base html which will help u.
bye
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top