I2C and Serout problems with 18F4525


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Location
    Australia
    Posts
    20

    Question I2C and Serout problems with 18F4525

    Dear All,

    The following code works fine for 16F777, but not work for 18F4525. Hope to get helps from you. The Led is flashing OK, but I2C, Serout, and string ABC do not work at all. Note that the slave is 16F747.

    ================================================== ===
    include "modedefs.bas"

    'DEFINE I2C_HOLD 1

    SCL VAR PORTC.3 ' Clock pin
    SDA VAR PORTC.4 ' Data pin
    LED var PORTB.7
    ABC var byte[2]
    Out var PORTD.2

    Address CON 2 ' Slave PIC 7-bit address

    OSCCON = %01101110 ' Use internal 4MHz clock
    ADCON1 = $0F ' Disable A/D convertor
    ' SSPADD = $09
    ' SSPCON1 = %00101000
    ' SSPCON2 = $FF
    TRISA = %00000000 ' PORTA all set to Output
    TRISB = %00000000
    TRISC = %00011000
    TRISD = %00000000
    TRISE = %00000000

    PORTA = 0
    PORTB = 0
    PORTC = 0
    PORTD = 0
    PORTE = 0
    ' LATA = 0
    ' LATB = 0
    ' LATC = 0
    ' LATD = 0
    ' LATE = 0

    SCL = 1
    SDA = 1

    ABC[0] = "A"
    ABC[1] = "B"
    goto loop

    FailedR:
    serout Out, n9600, ["Read fail"] ' I2C command timed out
    return

    FailedW:
    serout Out, n9600, ["write fail"] ' I2C command timed out
    return

    Loop:
    low led
    pause 500
    I2CWRITE SDA,SCL,Address,[127],FailedW
    pause 100
    I2CRead SDA,SCL,Address,[str ABC\2], FailedR ' Read two bytes from slave
    high led
    serout Out, n9600, [ABC[0], ABC[1], 13, 10] ' sent to PC
    pause 500
    Goto Loop

    END
    =============================================

    I made the changes of 18F4525.INC
    from
    __CONFIG _CONFIG1H, _OSC_XT_1H
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    to
    __CONFIG _CONFIG1H,_OSC_INTIO67_1H
    __CONFIG _CONFIG2H, _WDT_OFF_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H
    __CONFIG _CONFIG4L, _LVP_OFF_4L

    Best regards,

    Yuantu
    Yuantu Huang

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    weird, what about if you enable the Watch Dog Timer ?!?

    And what about if you use internal 8MHZ instead of 4MHZ with a DEFINE OSC 8 For 4Mhz, i'm not sure 9600 baud will work 100%

    Have you some filtering caps (0.1 ceramic + 10uF tantalum) close.. REALLY close to your PIC. 18F are a more noise sensitive than the 16F.
    Last edited by mister_e; - 1st March 2005 at 17:45.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2005
    Location
    Australia
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Dear Steve,

    I made it working as your suggestion although sometimes it doesn't go (seems no clock, it may be the circuit board problem). The following is the change of the code and cofiguration:

    code:
    ========================
    DEFINE OSC 8
    OSCCON = %01110111
    =======================

    cofiguration:
    ==============================================
    __CONFIG _CONFIG1H,_OSC_INTIO67_1H
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBADEN_OFF_3H
    __CONFIG _CONFIG4L, _LVP_OFF_4L & _ENHCPU_OFF_4L
    ==============================================

    Once again thank you very much.
    Yuantu Huang

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Great. Try reprogram your PIC with the lowest Brown-Out-voltage treshold too. Power-Up timer have to bet set too.

    Of course noisy supply line and 'weird contact' on a board can do bad results. PIC18F series are really noise sensitive... use of external pull-ups instead of the internal seems to solve some problems. After some tests, Pull-ups lower than 4.7k give better result. i use 1K in all my apps. For sure sink a bit more current but... it works.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Problem with I2C (24c32 eeprom)
    By lab310 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 5th February 2008, 09:00
  2. I need help with i2c memory
    By -c3- in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 23rd June 2005, 19:57
  3. problems with I2C.... and ideas why dosent work?
    By snood in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 26th April 2005, 12:54

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