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 CCS Technical Support

Software RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ysaacb



Joined: 12 Jun 2006
Posts: 19

View user's profile Send private message

Software RS232
PostPosted: Tue Sep 26, 2006 2:37 pm     Reply with quote

Hi Everibody
I've been working succsefuly with the HW usart of the 18F2620 and I want to add second one (software) for debug purpouses. I write a very simple code to try it but only recive garbage.

I've tried with different baud rates an recive different garbage

I'm using a HIN323CP (intelsil)

This is the code
Code:

#include <18f2620.h>
#device icd=true
#use delay(clock=19660800)
#fuses HS,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=modem,bits=8)
#use rs232(baud=9600,parity=N,xmit=PIN_B0,stream=PC,bits=8,INVERT)

void main()
{
   output_bit(PIN_B5,0);
   fputs("ABCDEFG",pc);
}

Thanks for your colaboration

Ysaac :sad:
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Tue Sep 26, 2006 2:42 pm     Reply with quote

I didn't even look at this much.
Your code says print something and goto sleep.

ALWAYS HAVE A FOREVER loop in the code


Code:

#include <18f2620.h>
#device icd=true
#use delay(clock=19660800)
#fuses HS,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=modem,bits=8)
#use rs232(baud=9600,parity=N,xmit=PIN_B0,stream=PC,bits=8,INVERT)
//I use
//#use rs232(baud=9600,xmit=PIN_B0,invert,stream=DEBUG,disable_ints)
void main()
{
   output_bit(PIN_B5,0);
   fputs("ABCDEFG",pc);
   fprintf(PC,"Hello World!\n\r");
while(1);

}
ysaacb



Joined: 12 Jun 2006
Posts: 19

View user's profile Send private message

PostPosted: Wed Sep 27, 2006 7:57 am     Reply with quote

I delete the "INVERT" from the #USE RS-233 but the problem still persist.
I'm just trying to print some characters to the Hyperterminal but the first Bytes are always missing or garbage

Reagars

Ysaac
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Wed Sep 27, 2006 8:13 am     Reply with quote

Did you try the code I posted above? The big thing is while(1); This is a forever loop. That is while(1) is ALWAYS true, do the next statment, which is on the same line, which is the ; no statement at all
this makes a loop.((a forever loop.)) It never breaks out of the last statment.
you could code it as
while(2==2){
//nothing to do, sit here and loop.
}

You can't just guess, and delete the invert statement from #use rs232.

You have to understand how your circuit is wired and what the functions do.
The invert is used if your transmit pin of the PIC is NOT hooked to a
max232
type "LEVEL SHIFTER". The max232 changes the RS232 voltages(12v) to ttl type 5v and inverts it.

Some people (me) do this as a quick and dirty debug. You can use any pin. You may think running a 12V signal into the 5v PIC is bad, but if you use a 1k ohm resistor in series to limit the current, you'll be fine.
PIC pin--->1kohm---->pin2 of DB9 serial == INVERT

OR

PIC pin -->max232-->pin2 of DB9 serial ==((no invert in rs232))

I have never broke a chip using this technique in 3 years.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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