PDA

View Full Version : Serial Communication using 12F629



charudatt
- 13th March 2005, 09:05
Hello there,

I have a problem trying to send data to the serial port using PIC 12F629. The code is a very simple test program before I can actually send serial information on the key pressed on the Sony IR remote. I am using direct drive on Pin #2 via 1K resistor to the serial port.

My code is as follows:
@ DEVICE PIC12F629,INTRC_OSC_NOCLKOUT,WDT_ON,PWRT_OFF,BOD_O N,PROTECT_OFF,CPD_OFF,MCLR_OFF

' Define Osc 4 ' We're using a 4 MHz oscillator
TRISIO=0
CMCON=%00000111
Include "Modedefs.Bas"


RELAY VAR GPIO.2 ' Relay output
Ser VAR GPIO.4 ' Serial Out
I VAR BYTE ' TEMP VARIABLE

Welcomemsg:
SEROUT2 SER, 16780,["TEST" , 10] '2400 BAUD RATE

Loop:
TOGGLE RELAY
Pause 500
SEROUT2 ser , 16780 , [I , 10]
I = I +1
IF I = 250 THEN I = 0
goto Loop
end

Although I am getting data out , Its all garbage. Iam looking for 2400 baud rate communication.

regards
Charudatt.

Ron Marcus
- 13th March 2005, 14:38
I have found that with the internal oscillator devices, the output frequency may deviate enough to mess up the serout routines. If this is the case, try using the INTOSC configuration. Check the frequency, and adjust the oscillator callibration until it's as close to 1 MHz as possible. I have sent out 9600 baud this way, but it is not 100% reliable.

charudatt
- 13th March 2005, 14:56
Hello Ron,

I think that is the case !. Because , its not that I am not getting anything out, but just that its Garbage.

Can you suggest how to use the INTOSC Config in the code.

Earlier , I used the same code with F72 but with a Crystal and it all worked just fine.

But this code would , just not make sense on the Hyper terminal.

Thank you for your help.

Ron Marcus
- 13th March 2005, 23:07
[QUOTE=charudatt]Hello Ron,

I think that is the case !. Because , its not that I am not getting anything out, but just that its Garbage.

Can you suggest how to use the INTOSC Config in the code.

An easier way to do it, is to find out if the rate is too fast or too slow. This can be done with a frequency meter. If it is, for arguement sake, too fast, I would do a for next loop incrementing the serin2 baud rate number by one, until the character or word coming out of the pin is the right one.

Example: For A = 1 to 100
Serout2 pin,32768 + A,[dec A, "test"]
Next A

On the receive side, you should get the right number and right date when the baud rate is correct. Just add the number ti the baud number and all will be right with the world. If you don't have access to a meter, then try it above and below the proper number.

kattronics
- 14th March 2005, 00:19
First, Make sure u have a small Cap on the power supply! (.1uF) . If that dose not fix it then ,

Add this after your "fuses"
DEFINE OSCCAL_1K 1

Change this:
SEROUT2 SER, 16780,["TEST" , 10] '2400 BAUD RATE
To
SerOut GPIO.4,N2400,["Test" ,10]

charudatt
- 14th March 2005, 04:24
Kattronics:

I already tried what you said, with the DEFINE OSCCAL_1K 1 the PIC goes bonkers. Not sure what is wrong with it.

I also tried the SerOut GPIO.4,N2400,["Test" ,10] but no luck,

I think I would go with Ron's suggestion and try it out.

Nevertheless I succeeded in decoding Sony IR codes using the PIC ,which was my end intentions anyway, but just for the sake of testing out serial communication , I would compelete this experiment and post my results.

Thank you all.