Continue to Site

# serial port interface help

Status
Not open for further replies.

#### david90

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
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
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
check the crystal oscillator of your controller,crystal oscillator of your controller should be equal to that seen by your compiler.

#### david90

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
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
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

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
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

try the example codes from the pic list they have a lot of working codes examples in that website

#### david90

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.

Nice.

#### niket_304

##### Member level 4
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.