SEROUT2 fails on newer 18F2610


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Nov 2005
    Posts
    18

    Question SEROUT2 fails on newer 18F2610

    Hello,

    I've been programming 18F2610s for several years now without a problem.
    Now, I got a new batch of 18F2610s date coded 0804, and using the exact same code from several years it does not work. SEROUT2 sends out garbage.

    I have a couple of older PICs date coded 0427 and 0730 and they work just fine, but 12 newer ones just won't work.

    Is anybody aware of a silicon update that could affect SEROUT2 on this PIC?

    Is there a workaround for this?

    Any help will be greatly appreciated.

    Thanks, Gabriel

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gabrielg74 View Post
    Hello,
    I've been programming 18F2610s for several years now without a problem.
    Now, I got a new batch of 18F2610s date coded 0804, and using the exact same code from several years it does not work. SEROUT2 sends out garbage.
    I have a couple of older PICs date coded 0427 and 0730 and they work just fine, but 12 newer ones just won't work.
    Is anybody aware of a silicon update that could affect SEROUT2 on this PIC?
    Is there a workaround for this?
    Any help will be greatly appreciated.
    Thanks, Gabriel
    Internal or external oscillator?

  3. #3
    Join Date
    Nov 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    External, 20MHz crystal.
    Tried 5 different boards with the new PIC (fails) and with the old one (works ok).

    Gabriel

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gabrielg74 View Post
    External, 20MHz crystal.
    Tried 5 different boards with the new PIC (fails) and with the old one (works ok).

    Gabriel
    Just looked at the ERRATA sheets from Microchip.
    Nothing specific to that particular issue, but a lot of things that could be tied into it.
    Suggest paging thru them to see if you can find anything.

    Which version of PBP are you using?

  5. #5
    Join Date
    Nov 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    PBP 2.4.6.0

    Already checked the Errata and could not find anything that could be causing this.

    Gabriel

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gabrielg74 View Post
    PBP 2.4.6.0

    Already checked the Errata and could not find anything that could be causing this.

    Gabriel
    Well,,,,,,,,,,show the code. Maybe there's a bit changed in there somewhere.

  7. #7
    Join Date
    Nov 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    I tried changing wait times and serial speed and still does not work.

    Here is the offending code:

    '------------------------------------------------------------------------------
    'Initial config
    '------------------------------------------------------------------------------
    DEFINE OSC 20 'Osc 20MHz
    DEFINE NO_CLRWDT 1 'WDT inactive

    '------------------------------------------------------------------------------
    'Port definition
    '------------------------------------------------------------------------------
    SCL3W VAR PortA.0 'Puerto de reloj del RTC (3 wire)
    IO3W VAR PortA.1 'Puerto de datos del RTC (3 wire)
    RST3W VAR PortA.2 'Puerto de reset del RTC (3 wire)
    TXLCD VAR PortA.3 'Puerto de TX del LCD
    MCLRLCD VAR PortA.5 'Puerto de reset del LCD
    RARROW VAR PortB.0 'Boton a la derecha
    UARROW VAR PortB.1 'Boton hacia arriba
    DARROW VAR PortB.2 'Boton hacia abajo
    LARROW VAR PortB.3 'Boton a la izquierda
    TXPRTR VAR PortB.4 'Puerto serie asinc. para impresora TX
    RXPRTR VAR PortB.5 'Puerto serie asinc. para impresora RX
    KSWITCH VAR PortB.6 'Llave
    ACDETECT VAR PortB.7 'Deteccion de AC
    EE1 VAR PortC.0 'Habilita memoria EEPROM principal
    EE2 VAR PortC.1 'Habilita memoria EEPROM secundaria
    IROUT VAR PortC.2 'Salida serial IR
    SCLI2C VAR PortC.3 'Puerto de reloj I2C para EEPROMs
    SDAI2C VAR PortC.4 'Puerto de datos I2C para EEPROMs
    IRIN VAR PortC.5 'Entrada serial de IR
    TXPC VAR PortC.6 'Puerto serie asinc. para PC TX (impresora 2)
    RXPC VAR PortC.7 'Puerto serie asinc. para PC RX (impresora 2)

    main:
    '+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
    'Initialize PIC hardware
    '+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
    Init_Hardware:
    ASM
    movlw B'00111111'
    movwf ADCON1 ;Port A is digital I/O

    clrf PORTA ;Clear port A data latches
    clrf PORTB ;Clear port B data latches
    bsf PORTB,4 ;Printer port initial state
    clrf PORTC ;Clear port C data latches
    bsf PORTC,3 ;Initial state of RC3 (SCL)

    bcf INTCON2,RBPU ;Enable pull-ups on port B

    movlw B'00010010' ;RA1 & RA4 inputs
    movwf TRISA ;

    movlw B'11101111' ;RB4 output
    movwf TRISB ;

    movlw B'10110011' ;RC2 & RC3 outputs, RC6 & RC7 serial port
    movwf TRISC ;(TX y RX)

    ENDASM


    '+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
    'Initialize LCD
    '+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
    Init_LCD:
    PAUSE 1000 'Wait for everything to power up
    TXLCD=1 'Initial State of LCD comm line
    MCLRLCD=1 'Enable LCD
    PAUSE 100 'Wait 100ms for LCD to startup
    SEROUT2 TXLCD,84,["U"] 'Send a "U" to sync comm speed
    PAUSE 60
    SEROUT2 TXLCD,84,[$01] 'Clear LCD
    PAUSE 5
    SEROUT2 TXLCD,84,[$0C] 'Turn off insertion point
    PAUSE 5
    SEROUT2 TXLCD,84,["Control de Impr."]
    PAUSE 10
    SEROUT2 TXLCD,84,[$00,$40,"v 5.0b"]
    PAUSE 5000 'Display initial message for 5 seconds
    SEROUT2 TXLCD,84,[$01] 'Clear LCD
    PAUSE 50

    '+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++

    END

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gabrielg74 View Post
    DEFINE NO_CLRWDT 1 'WDT inactive
    Doesn't actually turn off the WDT. It just instructs PBP NOT to insert CLEARWDT instructions.
    Might actually be getting an WDT interrupt in the middle of the SEROUT2 execution.
    Check your programmer/.inc file settings.

  9. #9
    Join Date
    Nov 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    I have isolated the problem even more, it is not an instruction problem, it is a PORT A problem. If I set PortA.3 high and then set PortA.5 high, PortA.3 will ALWAYS go low. For example if I do this instructions:

    PortA.3 = 1
    PortA.5 = 1

    or

    TXLCD = 1
    MCLRLCD = 1

    or

    @ bsf PORTA,3
    @ bsf PORTA,5

    PortA.3 will ALWAYS go low after PortA.5 goes high.
    But if I reverse the instructions (first set PortA.5 then set PortA.3) it works OK.

    I don't have the slightest idea what is happening, but it is affecting my program only when used on PICs date coded 08XX.

    I hope anyone can help me solve this problem.

    Thanks,

    Gabriel

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


    Did you find this post helpful? Yes | No

    Default

    Change;

    TXLCD VAR PortA.3 'Puerto de TX del LCD
    MCLRLCD VAR PortA.5 'Puerto de reset del LCD

    to;

    TXLCD VAR LATA.3 'Puerto de TX del LCD
    MCLRLCD VAR LATA.5 'Puerto de reset del LCD

    Does it work now?
    Regards,

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

  11. #11
    Join Date
    Nov 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Thank you for your help. We solved the problem.
    I don't have an explanation, but it works now.
    All I did was change ADCON1=B'00111111' to ADCON1=B'00001111'
    And now it works just as expected on older and newer PICs.

    I still am interested in an explanation, so if anyone would like to elaborate....


    Thanks, Gabriel

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


    Did you find this post helpful? Yes | No

    Default

    Apparantly even with A/D disabled it's still causing problems when you have AN2 & AN3
    setup as Vref- & Vref+. Clearing ADCON1 bits 4 & 5 sets Vref to Vss & Vdd, and not these
    pins.

    The problem you describe sounds like read-modify-write, which is more of a problem when
    an output has external capacitance on it. By having ADCON1.4 = 1, AN3 is connected to
    an internal circuit for Vref+. This most likely is adding enough capacitance to cause the
    read-modify-write issue.

    What happens is when you set RA3, it does not change fast enough before you are setting
    RA5, so RA3 is read back in, then writen again on the write to RA5 causing a 0 to be writen
    back to RA3.

    This would also explain why it works when you reverse the order. I.E. RA5=1 then RA3=1.
    It works because the extra capacitance is not present on RA5.
    Last edited by Bruce; - 6th March 2008 at 00:27. Reason: P.S.
    Regards,

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

  13. #13
    Join Date
    Nov 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Thank you for your explanation.

    I could not find this in the Errata for this PIC. Maybe it is not documented.

    Gabriel

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


    Did you find this post helpful? Yes | No

    Default

    I doubt you will find anything on this in an errata doc. You should disconnect pins from the internal Vref circuit if they are not being used for Vref, and adjust your code as required to avoid read-modify-write problems.

    Writing to the LAT registers VS port registers on the 18F series takes care of r-m-w.
    Regards,

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

  15. #15
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gabrielg74 View Post
    Thank you for your explanation.
    I could not find this in the Errata for this PIC. Maybe it is not documented.
    Gabriel
    Like Brue said above, it's not neccessaily in the Errata sheets, but the datasheets themselves usually have a little blurb about R-M-W issues somewhere.
    It's a 'gotcha'. It'll get you this time...and it'll get you again probably in a few years.

Similar Threads

  1. Serout and 18F87J50
    By Glenn_Webber in forum Serial
    Replies: 8
    Last Post: - 20th November 2009, 14:26
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. SLOW Serin2 and Serout2
    By dragons_fire in forum General
    Replies: 3
    Last Post: - 26th June 2009, 02:38
  4. Serial communication fails after long pause
    By brid0030 in forum General
    Replies: 4
    Last Post: - 13th February 2008, 18:56
  5. Gps with 16f628
    By dragons_fire in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th June 2006, 03:38

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