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

12F675 RS232 software problem

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



Joined: 13 Nov 2007
Posts: 11

View user's profile Send private message

12F675 RS232 software problem
PostPosted: Mon Nov 19, 2007 2:58 pm     Reply with quote

I'm tring to send information using RS232 Software.
The problem is that when I send information, I get garbage!
I'm using a 12f675 with internal osc at 4MHz.
I just read the topic about this same issue, but there is nothing relevant, I`ve got a project almost finished, but I'm depending on this.
Here is the source code:

#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOCPD,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A3,bits=8)
#byte STATUS=0x03
#byte OSCCAL=0x90
#ROM 0x3FF= {0x34C0} // Calibration Word


int16 signal=0;

void adc(void){
signal=(read_adc()*0.488);
delay_us(50);
}

#INT_RA
void Serial_IN(){
char data=0;

if(kbhit())
switch((data=getch()))
{
case 'A':
putc('C');
break;

case 'B':
putc('A');
break;
}

data=input_a();
}


void main() {
int port=0;
float val=0;
//Load Factory Calibration Value Into OSCCAL
#asm
call 0x3FF
bsf STATUS,5
movwf OSCCAL
#endasm
//-------------------------------------------

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_ANALOG|VSS_VREF);
set_adc_channel(0);
enable_interrupts(INT_RA3);
enable_interrupts(GLOBAL);
port=input_a();

while(true){
adc();
printf("Test\r");
delay_ms(2000);
printf("%d",(int)(signal/10));
}
}

Thanks! Rolling Eyes
SherpaDoug



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

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 3:14 pm     Reply with quote

What is your compiler version?
EXACTLY what sort of "garbage" are you getting? Can you read in hex so we have the exact bit pattern? Could the data be inverted or the wrong baud rate?
_________________
The search for better is endless. Instead simply find very good and get the job done.
maritto



Joined: 13 Nov 2007
Posts: 11

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 4:28 pm     Reply with quote

when I simule it in proteus, it works perfectly!, but, when I connect the circuit to the Serial Com1, I just send garbage.
The baud rate, is exactly the same (the programmed, and the spected).
Using that code, in proteus worked, but when I use the circuit (the PIC works), using the MAX232 interface, It doesn't work!

It seems to repeat in some kind of patron, but it's not the information that I send, i think that the number of bits recibed it's rigth, for example:
printf("Test\n"); (I recibe)-> Usüt (something like that)

thanks![/u]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 5:11 pm     Reply with quote

I tested the program shown below and it works OK. It displays the
following output in the terminal window on a PC:
Quote:
Hello World


I compiled it with vs. 4.061. The PIC is running at +5v, and it's
connected to a MAX232A chip.
Code:
#include <12F675.h>
#fuses INTRC_IO, NOWDT, NOMCLR, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A3)

//===========================
void main()
{

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

while(1);
}
maritto



Joined: 13 Nov 2007
Posts: 11

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 9:37 pm     Reply with quote

Thanks, then I'll try this, lets see if it works!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

12f675 ?? PCM programmers file et al
PostPosted: Tue Nov 20, 2007 5:05 pm     Reply with quote

you mean you can implement soft RS-232 in that part and STILL have room enuf for a flea to dance in the code space thats left - with all 4 free GPIOS's
at your disposal ? HOW MUCH code SPACE IS Left to do something with after the soft RS232 is set up ?

i never even dreamed of trying that !!!
nice
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 5:38 pm     Reply with quote

Here is the report from the .LST file for the short program I posted
earlier in this thread.
Code:

  ROM used: 92 words (9%)
     Largest free fragment is 932
  RAM used: 6 (9%) at main() level
            7 (11%) worst case
  Stack:    1 locations


Be aware that CCS is doing the most simple type of software UART.
Of the three methods listed on this webpage, CCS is doing #3:
http://www.8052.com/faqs.phtml?FAQ=124758
maritto



Joined: 13 Nov 2007
Posts: 11

View user's profile Send private message

PostPosted: Wed Nov 21, 2007 11:21 am     Reply with quote

OK! I've been working a lot! I'm traying to install Linux jejeje.
I tried tha pice of code, but it continues sending garbage!
I don't know why!
I need to send:

"temp;temp_ref;delay"

just that, and recibe a code
'A', or 'S'
to ask for data, or setting temp_ref

It is a project, a temperature controlator.
This is sad! I hope you can helpme!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

i bet it is the BAUD rate
PostPosted: Wed Nov 21, 2007 11:51 am     Reply with quote

based on the Us..t response you read - i am pretty confident that the problem is baud rate related - maybe framing - either in your Pic program or on the receiving end - but probably on the receiving side

you really need to use a KNOWN working serial source to test your receiving program settings -BEFORE working with your pic
AND BTW YOU ARE using a max 232 or 222 or similar part to make the EIA RS-232 level interface - RIGHT ??if NOT using the proper interface level shifter ALL BETS ARE OFF anyway. you never talked about your hardware did you ?

any cheesy windows terminal program and a null modem cable - will let you work out for sure what the receiving baud rate really is - so long as you test first with a KNOWN baud rate you plan to use with the pic

only when you are SURE of your receive terminal status should you revisit the PIC code - i just tried this with the same part you are using - and found it to be no problem.

verifying your receiver settings before you start with a new untested source device is serial com course level 100 stuff - so to solve this - all you have to do is get with the program - ok ?
Very Happy
maritto



Joined: 13 Nov 2007
Posts: 11

View user's profile Send private message

PostPosted: Thu Nov 22, 2007 10:56 am     Reply with quote

Yes! I'm using a max232, and the circuit, also the interface (serial cable and circuit), is tested, I succesfuly used it with a Pic16F877, probably there is an error with the software terminal, I'll try to check it's configuration, I'm using the serial port monitor utility.
Witch is the recomended baud rate?
Could you showme an example of configuration (number of bits! could it be the problem?! I'm setting it to 8)

Thanks for your help!
maritto



Joined: 13 Nov 2007
Posts: 11

View user's profile Send private message

PostPosted: Thu Nov 22, 2007 4:08 pm     Reply with quote

It's working!!!!
I'm really sorry, the voltage was wrong!
And the max 232, was sending garbage!
Now it works!
THANKS A LOT for you help!
Also I learned a lot about RS232 in my research to solve this problem!Thanks again!

Your help was very usefull.
ricardjc



Joined: 25 Nov 2007
Posts: 1
Location: Gatineau, QC, CA

View user's profile Send private message

same problem
PostPosted: Sun Nov 25, 2007 12:10 pm     Reply with quote

maritto wrote:
It's working!!!!
I'm really sorry, the voltage was wrong!
And the max 232, was sending garbage!
Now it works!
THANKS A LOT for you help!
Also I learned a lot about RS232 in my research to solve this problem!Thanks again!

Your help was very usefull.


Hi

I'm having the same problem. Just trying to pass variables from 18F4550 thru the RS232 port and I get garbage like :

count1 uîÈß count2 uîÈß chan1 uîÈß

where strange values should be int8 values.

What exactly did you do to get it working?

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 4:21 pm     Reply with quote

Start with a small test program, as shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=25737&start=2

If it doesn't work, then:

1. Post your test program.

2. Post your compiler version.
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