Comunication between 12F683 & 16F84A with serin2/serout2


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Default Comunication between 12F683 & 16F84A with serin2/serout2

    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.
    Last edited by kklim29; - 28th April 2010 at 20:09. Reason: Wrong device code

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    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.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hmm..
    Can you post the whole code(s) and actual configs?
    Must be something else the problem other than the lines shown.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Arrow

    Here is the code use for 12F683
    Code:
       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:
    Code:
    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
    Last edited by mackrackit; - 29th April 2010 at 09:29. Reason: Add Code Tags

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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)
    Code:
    DEFINE OSC 4
    And double check the ANSEL settings.
    I think you have GPIO.5 set for analog. Should be
    Code:
    ANSEL   = %000011111
    BTW. I added code tags for you. Makes it much easier to read on the forum.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    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?

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Lightbulb

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try changing serout2 datain,813,["B",dec tmp] to serout2 datain,813,["B", tmp]
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    Join Date
    Apr 2010
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    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

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kklim29 View Post
    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
    So, I'm afraid you have to turn to a 16F88 or equ. 14 pins device ... ( 16F684? )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts