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 support@ccsinfo.com

Getting Garbage from RS-232

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







Getting Garbage from RS-232
PostPosted: Fri Oct 06, 2006 12:49 pm     Reply with quote

Hi, i am tring to get my PIC16F690 to commuicate with my PC using MAX232, i am able to connect to the PIC, all i am getting is garbage.. i am getting extended ASCII code... ican't find any information on solving the problem..

please help me!!!!

this is my code:
-----------------------------
#include "C:\Documents and Settings\Rohan\Desktop\PicTest\test.h"

#bit C1=0x7.0
#bit C2=0x7.1
#bit C3=0x7.2

void main() {

int xBlinker=0; // Create Variable
Int Xcounter=0;

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_8MHZ);


set_tris_a(C1);
set_tris_b(C2);
set_tris_c(C3);


while (Xcounter <=257)
{

xCounter+=1;

delay_ms(1);

//Create Auto switch !
if (xBlinker==0) {
printf("LED ON");
C1=xBlinker;
C2=xBlinker;
C3=xBlinker;
xBlinker=1;
} else if (xBlinker==1) {
printf("LED OFF");
C1=xBlinker;
C2=xBlinker;
C3=xBlinker;
xBlinker=0;
}
}



// printf("Hello World\n");

C1=1;
C2=1;
C3=1;

//delay_ms(1000);

// C1=0;
//C2=0;
// C3=0;

}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Oct 06, 2006 1:28 pm     Reply with quote

Show us your full header including the #use RS232 line.

Your problem is likely either a wrong baud rate, which could be due to a wrong declairation or a bad clock, or wrong voltage levels like inversion or using TTL where you should use RS232 levels or vise versa. The best tool to troubleshoot these things is an oscilloscope.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Zulander
Guest







Header files
PostPosted: Fri Oct 06, 2006 1:39 pm     Reply with quote

This is the Header file..

#include <16F690.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#use delay(clock=20000000)

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
Ttelmah
Guest







PostPosted: Fri Oct 06, 2006 2:41 pm     Reply with quote

What is your oscillator (crystal, or external module). You need a fuse setting for this. The default fuses for this will be for RC oscillator.

Best Wishes
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Oct 06, 2006 2:44 pm     Reply with quote

First I'd forget your code and try the simplest possible code
main
{
while(true)
{
printf("x");
}
}
You've been advised to double check the baud rate etc to make sure the PC is no different.
If that doesn't work check the wiring from the xmt pin on the pic to the MAX232 and out to the RX pin on the PC.
Thousands can make this work so assume it is you're code and or your wiring and trple check if necessary.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 06, 2006 2:54 pm     Reply with quote

Quote:
#bit C1=0x7.0
#bit C2=0x7.1
#bit C3=0x7.2

set_tris_a(C1);
set_tris_b(C2);
set_tris_c(C3);


The stuff shown in bold is totally incorrect. You've defined 3 bits on
port C, and then you're using those bit definitions to set TRIS on ports
A, B, and C. This is wrong. My advice is to get rid of all the #bit
statements and the set_tris statements and just use the CCS pin i/o
functions, such as output_low() and output_high().


Quote:
Int Xcounter=0;

while (Xcounter <=257)
{

In CCS, an 'int' is an unsigned 8-bit integer. It can only hold a value
from 0 to 255. It can't hold 257. You need to declare the variable as
'int16'.
Zulander
Guest







Problem solved but does not help..
PostPosted: Wed Oct 11, 2006 9:48 pm     Reply with quote

Hi,
I have managed to solve the problem, the problem was that my Bafo BF-810 USB to Serial (DB9) Adapter does not seem to be working for some reason, I was getting garbage. When I used a direct connection to a serial port it worked fine..

So does anyone know a solution for my problem?? I need to work on my laptop and I need a converter.. USB to serial
Thank you
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