View previous topic :: View next topic |
Author |
Message |
maritto
Joined: 13 Nov 2007 Posts: 11
|
12F675 RS232 software problem |
Posted: Mon Nov 19, 2007 2:58 pm |
|
|
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! |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Nov 19, 2007 3:14 pm |
|
|
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
|
|
Posted: Mon Nov 19, 2007 4:28 pm |
|
|
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
|
|
Posted: Mon Nov 19, 2007 5:11 pm |
|
|
I tested the program shown below and it works OK. It displays the
following output in the terminal window on a PC:
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
|
|
Posted: Mon Nov 19, 2007 9:37 pm |
|
|
Thanks, then I'll try this, lets see if it works! |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
12f675 ?? PCM programmers file et al |
Posted: Tue Nov 20, 2007 5:05 pm |
|
|
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
|
|
Posted: Tue Nov 20, 2007 5:38 pm |
|
|
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
|
|
Posted: Wed Nov 21, 2007 11:21 am |
|
|
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
|
i bet it is the BAUD rate |
Posted: Wed Nov 21, 2007 11:51 am |
|
|
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 ?
|
|
|
maritto
Joined: 13 Nov 2007 Posts: 11
|
|
Posted: Thu Nov 22, 2007 10:56 am |
|
|
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
|
|
Posted: Thu Nov 22, 2007 4:08 pm |
|
|
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
|
same problem |
Posted: Sun Nov 25, 2007 12:10 pm |
|
|
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
|
|
|
|