PDA

View Full Version : Using 16f676 with comms



Peter1960
- 7th September 2005, 08:58
Hi,

Usind debug and setting the correct pins, there should be no reason that 16f676 for it to send and reeive rs232 data?

I have setup up CMCON =7 ( comparators off)
ANSEL = 7 (A-D 0,1,2 rest digital)
ADCON0.7 = 1 (right justify)
ADCON0.6 = 1 (ext vref)

DEFINE DEBUG_REG PortC
DEFINE DEBUG_BIT 1
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1

after turnon and wait I send

DEBUG REP $00\8,13,10,"Hello"

but no "hello"

any inputs?

thnks

Peter

Melanie
- 7th September 2005, 11:17
Two things...

Firstly check the SPELLING of your DEFINES. They have to be EXACTLY right, any typo's will NOT be flagged as an error. You might also want to set PortC as all CAPS ie PORTC in the DEFINE statement.

Finally, although it should not affect transmission, some terminal programs only display what you're sending after receiving a CR, LF... so try...

DEBUG REP $00\8,13,10,"Hello",13,10

You should be in business. If you haven't got a crystal or resonator as OSC to your PIC, drop down in speed as it's unlikely you'll get relaible comms at 9600 on the internal or RC oscillator.

CocaColaKid
- 7th September 2005, 14:23
I would suspect the PortC thing to be the source of the trouble since the DEFINE lines are case sensitive.

Peter1960
- 8th September 2005, 01:16
Thks,

PORTA, PORTC worked well.

Peter

CocaColaKid
- 8th September 2005, 12:55
Good to hear Peter. Thanks for the update.

charudatt
- 28th October 2005, 13:00
Instead of starting a new thread , I thought of just adding my problems story to this one.

I am have a network of RS485 using 16F676 IC. I am having a big problem with communicating with the PC.

My harware config is :
Pin#1 of RS485 ----> MCLR/RA3
Pin#2&3 of RS485 --> RA4
Pin#4 of RS485 ---> RA5

My code is as follows:

@ DEVICE PIC16F676,INTRC_OSC_NOCLKOUT,WDT_ON,PWRT_OFF,BOD_O N,PROTECT_OFF,CPD_OFF,MCLR_OFF
Include "Modedefs.Bas"
ANSEL = 0 ' DISABLE THE ANALOG INPUT
CMCON = 7 ' DISABLE COMPARATOR ON PORTA
VRCON = 0 ' A/D Voltage reference disabled
TRISA = %00101000 ' SETS ALL PORTA PINS TO INPUT ' Set PORTAA to all input
TRISC = %00000000 ' 6 Pins - LCD and 2 Pins RF Module
LED VAR PORTC.5 ' LED (SINK)
SER_IN VAR PORTA.3 ' DATA INPUT PORT
DO VAR PORTA.5 ' DATA OUTPUT PORT
RS485 VAR PORTA.4 ' RS485 CONTROL PIN
HIGH RS485 :
' ----------------------------------------------------------------------
' ** Declare the Variables **
I VAR WORD ' TEMP VARIABLE
' ----------------------------------------------------------------------
HIGH RS485
LOOP:

FOR I = 16400 TO 16900 STEP 10
SEROUT2 DO,I,["VALUE: ", DEC I,10,13] ' FOR RS232
PAUSE 500
NEXT

GOTO LOOP
END

I seem to have lost my OSCAL value and I am trying to get a reliable comm using Hyperterminal software over RS485.

I am getting no Output on the Hyperterminal @2400

Can anyone help.

regards

Melanie
- 28th October 2005, 13:39
In case anyone's missed it in a hundred or so previous threads...

You are NEVER going to get repeatable reliable asynchronous communications at any speed without an xtal or resonator.

You might strike lucky, or you might tear your hair out chasing your tail all because your timing is out of spec.

I've written example code at 300 baud and posted them on this forum in great confidence only to have the code fail for someone somewhere. Async comms is just plain unreliable on internal or RC oscillators.

I have an application which uses a 12F675 (internal Oscillator factory calibrated) which is little more than an Alarm Beeper. It's important to hit the resonant frequency of the Piezo for maximum sound. Now the Piezo is quite tollerant... it likes 4kHz, but is happy from 3.8kHz thru 4.2kHz. Out of every batch of 100 we build, there's always two or three PICs that don't make the grade with the Factory Cal. Now that's a dumb beeper application - and here you want precision async timing with a Factory OSCAL value?

milestag
- 28th October 2005, 18:43
Thanks Melanie,

You may have just saved me a few days (or weeks) of frustration. I am reading this thread only 12 hours after sending in my PCB designs for fabrication. After months of design, redesign, double-check, triple-check, I now realize I WILL need a xtal for the bootloader and PC serial comms. (I had really hoped to get away with INTOSC on the PIC18F2525 and use those I/Os for other tasks...oh well).

LUCKILY.......I DID include the pads/traces for a xtal and caps....just in case......

I might try the INTOSC, but only AFTER I get it working with the xtal.

regards,
Jim

NavMicroSystems
- 28th October 2005, 19:16
...I have an application which uses a 12F675 (internal Oscillator factory calibrated) which is little more than an Alarm Beeper. It's important to hit the resonant frequency of the Piezo for maximum sound. Now the Piezo is quite tollerant... it likes 4kHz, but is happy from 3.8kHz thru 4.2kHz. Out of every batch of 100 we build, there's always two or three PICs that don't make the grade with the Factory Cal. Now that's a dumb beeper application - and here you want precision async timing with a Factory OSCAL value?

I have several 12F675's running in an NMEA application @4800 Baud on INTOSC.
They run absolutely reliable, but to achieve this you have got to finetune OSCCAL on every single PIC.
Accounting for the time this finetuning takes, I would never do this again.
Today I do not even use resonators on applications where serial comms are involved,
all my never designs include a crystal and two caps.
At the end this is the less expensive solution since it doesn't require any calibration.

charudatt
- 28th October 2005, 20:01
Thank you folks. I guess , I have to redesign the board using 16F72 IC.

Hence forth I shall always remember to use a Xtal where necessary.

regards

Charudatt