PDA

View Full Version : Comunication between 12F683 & 16F84A with serin2/serout2



kklim29
- 28th April 2010, 19:04
I'm working on a project which need to send data from 12F683 to 16F84A. I'm using a 4MHz crystal on 84A & configure 683 to use internal 4MHz clock. I can see 12F683 is sending data out with a scope but 16F84A is not responding (data no showing in 16X2 LCD). It work when I replace 12F683 with 16F84A.

12F683 code:
SEROUT2 GPIO.5,813 ["A", tmp]

16F84A code:
serin2 PORT5.4,813,[WAIT("A"),dec CONT2]

Anyone know what's the problem? Thanks.

mackrackit
- 28th April 2010, 19:09
serin2 PORT5.4,813,[WAIT("A"),dec CONT2]
PORT5 ???

Typo??

But you may also want to check to see if the ADC is turned off for the pins you are using.

kklim29
- 28th April 2010, 19:23
PORT5 ???

Typo??

But you may also want to check to see if the ADC is turned off for the pins you are using.

Sorry, should be PORTB.5 for the 16F84A.

I'm using the ADC to measure the analog signal on GPIO.0,1,2 &4, GPIO.5 is digital. So I can send the result to 16F84A to display on a LCD.

mackrackit
- 28th April 2010, 19:29
Hmm..
Can you post the whole code(s) and actual configs?
Must be something else the problem other than the lines shown.

kklim29
- 29th April 2010, 07:48
Here is the code use for 12F683


include "modedefs.bas"

DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

ANSEL = %00111111 ' Set all to A/D, A/D clock = Frc
TRISIO = %0011111 ' GP.5 = serial out, rest inputs
OSCCON = %01100000 ' Internal 4MHz osc


tmp var byte
RESULT VAR word[8] ' 8-BYTE ARRAY STORAGE FOR 4 A/D CONVERSIONS
J VAR BYTE ' A/D CHANNEL NUMBER BYTE VARIABLE
resul var byte
datain var GPIO.5
b var byte

tmp = 0

MAIN:
pause 1000 'Wait for 16F84A send data to LCD
tmp = tmp + 1
if tmp > 9 then tmp = 0
for b = 1 to 4
serout2 datain,813,["B",dec tmp]
next b
goto MAIN

and code for 16F84A:


include "modedefs.bas"

rly VAR PORTB.7 'relay
voltrelay var PORTB.6 'Relay Voltage control
datain var PORTB.5 'Read serial data from adc
sw1 VAR PORTB.0
sw2 VAR PORTB.1
cont2 VAR byte
'RESULT VAR word
typ VAR BYTE
b VAR BYTE 'If.. Then..

TRISA = %00000000
TRISB = %00000111

rly = 0
voltrelay = 0
b = 0
typ = 0


vslt: lcdout $fe, 1
pause 50
lcdout "1.Relay Voltage"
serin2 datain,813,[WAIT("B"),cont2]
lcdout $fe, $c0, "2.Enter", #cont2
goto vslt

mackrackit
- 29th April 2010, 08:40
Two things I see after a quick look...
You need to tell PBP what the OSC speed is. To do this add the following to the top portion of your code(s)


DEFINE OSC 4
And double check the ANSEL settings.
I think you have GPIO.5 set for analog. Should be



ANSEL = %000011111
BTW. I added code tags for you. Makes it much easier to read on the forum.

kklim29
- 29th April 2010, 11:39
Still not working. I also try set all the port to digital (ANSEL = %00000000) still not showing anything on LCD. Hardware connection checked. Do you think is a hardware issue?

Acetronics2
- 29th April 2010, 12:22
Hi, Kklim

could you " twist" somewhat the OSCTUNE register of the 683 ??? ... just to get a precise match with the '84 oscillator frequency ...

may be just use the " blinky led " program and trim the 683 osc frequency to that you've measured on the '84 ...

internal osc is " not so good " if you need frequ. matching ...

Alain

Bruce
- 29th April 2010, 16:42
Try changing serout2 datain,813,["B",dec tmp] to serout2 datain,813,["B", tmp]

kklim29
- 29th April 2010, 17:39
Hi all,
I capture 2 waveform with a scope from 84A to 84A which work fine and 683 to 84A (no data) and Alain is correct, 683 waveform is shorter (Faster) then the 84A, after playing with the OSCTUNE, every 10 data send, only 1 data is show on the LCD. Also try change the Baud Rate from 813 to 1646 & 188, no data show.:(

Looks like device with internal clock is no good for sending data to a device with external clock:confused:

Acetronics2
- 29th April 2010, 18:16
Hi all,
I capture 2 waveform with a scope from 84A to 84A which work fine and 683 to 84A (no data) and Alain is correct, 683 waveform is shorter (Faster) then the 84A, after playing with the OSCTUNE, every 10 data send, only 1 data is show on the LCD. Also try change the Baud Rate from 813 to 1646 & 188, no data show.:(

Looks like device with internal clock is no good for sending data to a device with external clock:confused:

So, I'm afraid you have to turn to a 16F88 or equ. 14 pins device ... ( 16F684? )

Alain