SERIN2 not working with 16F628


Closed Thread
Results 1 to 4 of 4
  1. #1
    d1camero's Avatar
    d1camero Guest

    Default SERIN2 not working with 16F628

    I have searched long an hard in the datasheets, forum and archive, but I am unable to get my 16F628 to receive any data from a 12F675 with SERIN2.

    I have the 16F628 acting as a master, with a 12F675 being the slave unit. The 628 sends a bit of data, then does a SERIN2 WAIT. The slave receives the data and replies back with a number.

    I have connected a logic analyzer, and the data is being sent from the master to slave and the slave is responding. The Logic analyzer interprets the data correctly at 2400 8N1. Yet the 628 master times out.

    Things to note:
    <ul>
    <li>16F628 is using an external 10Mhz resonator
    <li>Programmer for 16f628 is a ISP Pro 0818
    <li>12F675 is using a <b>calibrated</b> internal oscillator
    </ul>

    I have reduced this down to small test programs. Here is the 16F628 master code:

    <table border=1><tr><td>
    <code>
    @ Device PIC16F628,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_ON,BOD_O FF,LVP_OFF, CPD_OFF

    DEFINE OSC 10

    DEFINE CHAR_PACING 2400

    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 1

    Counter var Byte

    debug "Initializing...",13,10

    CMCON = %00000111
    TRISA = %00000010
    TRISB = %00000000
    VRCON = %00000000
    INTCON = %00000000
    RCSTA = %00000000
    TXSTA = %00000000
    SPBRG = %00000000

    pause 1000

    loop:

    pause 1000
    debug "Sending to slave...",13,10

    ' send out some stuff
    SEROUT2 porta.0, 16780, ["hello"]

    ' wait and read
    SERIN2 porta.1, 16780, 300, TimeOut, [WAIT("SYNC"), Counter]
    DEBUG "Got from slave:", DEC Counter, 13, 10

    Timeout:
    DEBUG "Timeout from slave", 13, 10

    goto loop


    </code>
    </td></tr></table>

    Here is the 12F675 slave code:

    <table border=1><tr><td>
    <code>
    @ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_ON,BOD_O FF 'sets configuration

    Counter var byte

    CMCON = %00000111
    TRISIO = %00000000
    ANSEL = %00000000

    Pause 100

    Counter = 0
    loop:
    Serin2 gpio.2, 16780, [WAIT("hello")]
    PAuse 2
    SEROUT2 gpio.4, 16780, ["SYNC", Counter]
    Counter = Counter + 1

    goto loop
    </code>
    </td></tr></table>

    A JPG of the Logic Analyzer is attached. Your help is very much appreciated.

    thanks
    Don
    Attached Images Attached Images  

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Try a couple or three things here...

    1. Increase the Pause on reply to 200mS from 2mS... and if this works, work down from that...

    2. Drop your baud rate to 300 and work up from that... even with a calibrated internal oscillator you may still significantly deviate from 4MHz...

    3. Prefix your Transmit string from the slave with say eight nulls... like so...

    SEROUT2 gpio.4, 16780, [REP $00\8,"SYNC", Counter]

    This will shift-out any lurking line garbage before good data arrives...

    You may need to impliment any or all of these options.

  3. #3
    d1camero's Avatar
    d1camero Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the tips Melanie. No such luck. Here is what I have tried:

    1. replace twisted pair wires with straight wires
    2. remove Tx and Rx 10k resistors (capacitance on the line)
    3. put REP $00\8 in slave transmit
    4. put in 200ms pause between slave SERIN2 and SEROUT2
    5. drop everything to 300 baud
    6. put a "HIGH porta.1" (Master Rx port) in initialization
    7. move master Rx port to B5

    I must stress, that I can see all this data clearly on the logic analyzer, which is interpreting the 300 8N1 just fine.

    Also, I tried the code with another 12F675 as master and it works (with port name changes of course).

    I am thinking the problem may be in the area of:

    1. I fried something on the chip (I do not have another 16F628 to test)
    2. I am not initializing some 16F628 specific register properly

    Any other ideas would be greatly appreciated.

    thanks
    Don

  4. #4
    d1camero's Avatar
    d1camero Guest


    Did you find this post helpful? Yes | No

    Default

    Once again Bruce came to the rescue. With the 12F675 and using the internal oscillator, I <b><i>must</b></i> add the line:
    <code>
    DEFINE OSCCAL_1K 1
    </code>

    This is required to tell PBP to fetch and use the factory calibarted value. Even though I had calibrated the value, without the above DEFINE, I wasn't even using it!

    Everything works just fine now.

    Thanks again for the help Melanie,

    Don

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. LOW PORTA cause serin2 not working.
    By mikewen in forum Serial
    Replies: 7
    Last Post: - 28th August 2009, 04:18
  3. Getting SERIN2 to work?
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 20:10
  4. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  5. Hserin not working...
    By robert0 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd August 2005, 12:25

Members who have read this thread : 0

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