I2CWRITE and 18F4680


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 41
  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151

    Question I2CWRITE and 18F4680

    Hello All-
    I have what I suspect is a simple error on my part - but I can not seem to see it (trees?)

    I am trying to use a MCP23016 and the I2C commands in PBP on an 18f4680. I have used I2C commands on another proc and it worked great with the RTC that I needed - but, this time I can not seem to get it to work.

    What I have done:
    1. Pulled both the SCL and SDA lines up to +5.
    2. All 3 address lines are grounded.
    3. 3.9k and 33pF used for CLKIN.
    4. All 3 pins (1,8,19) are grounded.
    5. TP is left floating
    6. Written test code to wiggle the chip which is surface mount - I can not seem to get an output from the 23016.
    Observed:
    By a scope on the SDA and SCL lines I found that SDA is LOW all the time and the SCL is HIGH all the time. So I wrote test code to toggle these 2 lines and I observed the 2 lines behaving as I would suspect.

    It seems as if when I use the PBP command I2CWRITE it does not wiggle the 2 lines needed. I believe I must get this fundamental thing to work before I attempt to debug how to communicate with the 23016.

    I have read several posts regarding the 23016 which is why I decided to try this part (hope I get this work ).

    I have set the registers according to other posts found on this forum for this chip (thanks Melanie) but it seems as if this command is not working (which I know is not the case) so I am perplexed.....

    Summary-
    I can write test code to toggle the PORTC.4 pin (SDA) and the PORTC.3 pin (SCL) but I do not see any change when writing in a loop to the 23016 using I2CWRITE. I know the chip is working because I have other LEDs that I toggle in the loop to ensure we are not hung somewhere. It is working at 40 MHz - should I try a slower speed?

    Any ideas?

    Thanks in advance,
    Steve

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ecoli-557 View Post
    I have what I suspect is a simple error on my part - but I can not seem to see it (trees?)
    One error...no code shown...

    It is working at 40 MHz - should I try a slower speed?
    Have you tried? If you're using 40Mhz, chances are that you're using the internal PLL. Changing to 10Mhz would be a simple 4xPLL bit change... By definition, it would be slower.

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    I am using an external oscillator and not the internals. I will post the test code - no problem but what I can't get is WHY the pins don't toggle when I use the I2C command - they should shouldn't they?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ecoli-557 View Post
    I am using an external oscillator and not the internals.
    I know that. And if you read the datasheet you'll see references to the 4xPLL. You must be using an external 40Mhz clock if you're not using the internal PLL.

    I will post the test code - no problem but what I can't get is WHY the pins don't toggle when I use the I2C command - they should shouldn't they?
    Then post the code...

  5. #5
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Post

    Code I am using is shown below- The remarked lines are for FULL use.........
    When I manually toggle both I2C pins by the same method I use for the 'heartbeat' LED, they work as they should. (Had to cut code to 10,000 chars <grin>).
    '---------------------------------------------------------------------------------------
    'Define configuration bits - 'Set for using PIC18F4680 - 'Program using the USB MELABS programmer
    '*** NOTICE ***
    'The INC file in PBP has been modified to allow TOTAL CONFIGURATION of the fuses!

    @ __CONFIG _CONFIG1H, _OSC_ECIO_1H & _FCMEN_ON_1H
    'External oscillator, RA6 GIO
    'Fail-safe clk monitor ENABLED
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_BOHW_2L
    'Power up Timer ENABLED
    'Brown-out reset ENABLED in h-ware only
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H
    'Watchdog DISABLED
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _PBADEN_OFF_3H
    'MCLR is DISABLED, RE3 is INPUT
    'PORTB is DIGITAL on reset
    @ __CONFIG _CONFIG4L, _LVP_ON_4L & _STVREN_ON_4L & _XINST_ON_4L & _DEBUG_OFF_4L
    'Single supply ICSP ENABLED
    'Stack Overflow reset is ENABLED
    'Enhanced CPU is ENABLED
    'Background debugger DISABLED
    @ __CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L & _CP3_ON_5L
    'Code Protect Block 0, 1, 2, 3
    '---------------------------------------------------------------------------------------
    'Define the oscillator or crystal used
    DEFINE OSC 40 '40 MHz oscillator, one clk input
    INCLUDE "MODEDEFS.BAS" 'Include Shiftin/out modes if we need them
    '---------------------------------------------------------------------------------------
    define LCD_DREG PORTA
    define LCD_DBIT 0
    define LCD_RSREG PORTA
    define LCD_RSBIT 6
    define LCD_EREG PORTA
    define LCD_EBIT 5
    define LCD_BITS 4 define LCD_LINES 4 define LCD_COMMANDUS 4000
    define LCD_DATAUS 100
    '---------------------------------------------------------------------------------------
    'Lets setup the MCP23016s
    ' define I2C_HOLD 1
    define I2C_SLOW
    '---------------------------------------------------------------------------------------
    'OKAY, Lets set up the registers.....
    CMCON=%00000111 'Disables comparators, Port A
    ADCON0=%00000000 'Turns off ADC, Port A
    ADCON1=%00001111
    CMCON =%00000111 'Turns OFF comparators
    CVRCON=%00000000 'DISABLES comparator voltage module
    ECCP1CON=%00000000 'DISABLES PWMs and such
    '---------------------------------------------------------------------------------------
    'Direction registers
    TRISA = %10000000 'Set PORTA to all output
    TRISB = %11111111 'set all the pins of PORTB to INPUT
    TRISC = %10000111 'Set RC6 (TX), RC3 (SCL), RC4 (SDA)
    'Set RC7 (RX), RC0-RC2 are 3 address lines
    TRISD = %00000000 'Set PORTD to outputs
    TRISE = %00000000 'Set PORTE to outputs except RE3 which can ONLY be input
    '---------------------------------------------------------------------------------------
    'Additional I/O Definitions
    fault var PORTE.1 'FAULT output, low active (LED and Sonalert)
    heart var PORTE.0 'Heartbeat to know we are online
    CTS Var PORTE.2 'Goes high to xmit on RS485
    idata var PORTC.4 'I2C data pin - put 4.7k pullup!
    iclock var PORTC.3 'I2C clock pin - put 4.7k pullup!
    'Setup MCP23016; GP1.0-GP1.7 as inputs, GP0.0-GP0.7 as outputs
    '---------------------------------------------------------------------------------------
    'Variable List
    p_addr var byte 'Address of this processor
    K var byte 'Hex convertor variable
    i var byte 'Loop variable
    s var byte 'Seconds placeholder
    m var byte 'Minutes placeholder
    timers var byte[8] 'An array of 8 bytes to function as timers
    door var byte 'Loop counter
    DPI var byte
    locks var byte
    loop var byte
    i2c_addr var byte 'Address variable for the MCP23016
    i2cdoor var byte[8] 'An array of 8 bytes for I2C doors
    i2cdpi var byte[8] 'An array of 8 bytes for I2C Door Position
    i2cswitch var byte
    i2cled var byte
    '################################################# ############
    '# We are going to start this Pig!
    '################################################# ############
    init:
    pause 1000 'Hold here for a bit while things IPL......
    heart=1 'Turns off HEARTBEAT led
    fault=1 'Turns off FAULT led
    for i2c_addr=0 to 7
    ' i2c_addr=$20 'address 0 for the test
    i2cwrite idata,iclock,$06,i2c_addr,[$00,$FF] 'Sets GP0.0-GP0.7 as OUTPUTS
    pause 20
    i2cwrite idata,iclock,$07,i2c_addr,[$FF,$00] 'Sets GP1.0-GP1.7 as INPUTS
    pause 20
    next i2c_addr
    '################################################# ############
    '# We go around the rest of the subroutines
    '################################################# ############
    Initialize:
    goto startmain 'Jumps around subroutines

    '################################################# ############
    '# Subroutines
    '################################################# ############
    dly300: pause 300
    return

    initlcd:lcdout $fe,1 'Inits the lcd
    return

    get_addr:
    p_addr = PORTC & %00000111
    return

    chirp: for i=1 to 3
    low fault
    pause 50
    high fault
    pause 50
    next i
    return


    errori2c:
    lcdout $FE,2," "
    lcdout $FE,$C0," "
    lcdout $FE,$94,"No ACK from I2C dev "
    lcdout $FE,$D4," "
    pause 2000
    return
    '################################################# ############
    ' Hokay boyz, here we go......
    '################################################# ############
    startmain:
    'This is where it breaks down. I do not get any signals that change at the DATA and CLOCK pins on the proc.
    'DATA pin stays low and the CLOCK pin stays high.
    'I changed this short test area to pulse both pins in a tight loop
    'and that was just fine.
    'It is as if the I2C portion died! But, I am sure something I have done.......
    'I have checked and double-checked the I2C statements and they look fine.....

    check: gosub get_addr 'Just as a check of what addr the board is....for diagnostic
    loop=loop+1 'loop counter for heartbeat led 'pulse'

    ' i2c_addr=$20
    ' i2cread idata,iclock,$01,i2c_addr,[i2cswitch],errori2c
    pause 20 'Pause cause apparently we need to
    '' next i2c_addr 'Go get the next set of switches
    i2c_addr=0
    i2cwrite idata,iclock,0,0,[loop],errori2c
    pause 10 'Display for a while
    if loop=<10 then low heart 'A way to turn off the heartbeat pulse

    if loop=>11 then high heart 'A way to turn on heartbeat pulse

    if loop=20 then loop=0 'Resets us so we know we are alive
    goto check

    end

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


    Did you find this post helpful? Yes | No

    Default

    @ __CONFIG _CONFIG4L, _LVP_ON_4L & _STVREN_ON_4L & _XINST_ON_4L & _DEBUG_OFF_4L
    'Single supply ICSP ENABLED
    'Stack Overflow reset is ENABLED
    'Enhanced CPU is ENABLED
    Unless your programmer use this pin to program your PIC, high unlikely, you want to use LVP_OFF, unless it may not work as expected.

    Second test, use the internal OSC or lower value for the external.
    Steve

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

  7. #7
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    Thanks to both.
    Mr. E, I have changed the code to:
    @ __CONFIG _CONFIG4L, _LVP_OFF_4L & _STVREN_ON_4L & _XINST_ON_4L & _DEBUG_OFF_4L

    AND changed the oscillator to 20 MHz:
    DEFINE OSC 20

    and now BOTH lines are low all the time.......

    This is confounding, I am certain it will be a simple thing but I can not see it..... however, I do smell a lot of pine....... <grin>.

    Again, any help no matter how critical would be appreciated. Datasheet reading have proved as helpful as the tea readings.......

  8. #8
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    UPDATE-
    I built another test board (had several made overseas) and it does the same thing. Also tried another 6 pin programming cable - same thing.

    Tried different I2C defines such as
    define I2C_HOLD 1
    define I2C_SLOW

    with no luck, lines are either fixed at both high or one is high and the other is low - this should be telling me something - just don't know what it is.......

  9. #9
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    OK, I have tried more things, but no difference:
    i2cwrite idata,iclock,$2E,$06,[$00,$00]
    pause 20

    The idea is to force the R/W bit (0) to low for a write to the registers and telling the 23016 that both ports are outputs.

    BOTH the clock and data lines from the proc are high and do not wiggle at all under I2C commands but still can be made to wiggle under the HIGH and LOW coomands for individual pins.

    Still appears that no matter what I try to do with the I2C commands, the pins are silent.....

  10. #10
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    OK, more news which leads me to wonder if I2C commands work on this 18F4680 device.
    I changed the clk and data pins to the serial pins on which I have status LEDs for the serial part when I get to that.
    The LEDs did not toggle as they should either.

    Does anyone know how to troubleshoot the compiled code to see if this is compiling correctly?

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


    Did you find this post helpful? Yes | No

    Default

    Are you using a OSC module or crystal?
    Steve

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

  12. #12
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Oscillator

    I am now using a 20 MHz oscillator fed into A.7
    I also tried downloading the MPASM again from the MELABS site - no change.....

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


    Did you find this post helpful? Yes | No

    Default

    Don't forget, the timeout label OF I2CWRITE perform a GOTO not a GOSUB, maybe why you have odd results.... stack underflow.

    What happen if you loop within the INIT section?
    Code:
    init:
            pause 1000 'Hold here for a bit while things IPL......
            LCDOUT $FE,1,"I'm alive!"
            heart=1 'Turns off HEARTBEAT led
            fault=1 'Turns off FAULT led
            for i2c_addr=0 to 7
                 i2cwrite idata,iclock,$06,i2c_addr,[$00,$FF] 'Sets GP0.0-GP0.7 as OUTPUTS
                 pause 20
                 i2cwrite idata,iclock,$07,i2c_addr,[$FF,$00] 'Sets GP1.0-GP1.7 as INPUTS
                 pause 20
                 next
            GOTO init
    Last edited by mister_e; - 16th May 2008 at 18:44.
    Steve

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

  14. #14
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Thanks for the response and interest.....

    Mr. E-
    I added a GOTO at the end of the INIT section (tight loop) and still the pins don't reflect any movement - they are both high.

    BTW, MPASM 5.14, MCS 2.3.0.0, PBP 2.47.

    I am no Guru but have coded before and this is driving me nuts! 2 different board designs but using the same chip gives the same symptom.......I swear it seems that the command offers no response.

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


    Did you find this post helpful? Yes | No

    Default

    Is the LCD's working?
    Steve

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

  16. #16
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Everything else IS working but not the I2C command

    Yes, all esle is working as expected. When I start a project I use the LCD as a debugging tool and all the messages I write to it are working. ALso the heartbeat LED is blinking showing me that I am looping in the main part and that the proc is counting correctly.

    Everything BUT the I2C commands - nothing from the pin!!

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


    Did you find this post helpful? Yes | No

    Default

    Well that's strange... i have activity here on both pins with the same PIC, but 20MHZ external crystal (not the problem here as your LCD work)

    PBP 2.50, MPASM 5.20.

    I would check for a short somewhere...
    Steve

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

  18. #18
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default No shorts

    Mr. E-
    I used the 2 pins in a diagnostic way and toggled them the same way I toggle the 'heartbeat' LED. Both the data and clocks pins echoed the 'heartbeat' LED so I believe there are no shorts.
    I did this before but wanted to do it again just to be sure.
    if loop=<10 then low heart 'A way to turn off the heartbeat pulse
    if loop=<10 then low iclock
    if loop=>11 then high heart 'A way to turn on heartbeat pulse
    if loop=>11 then high iclock
    if loop=20 then loop=0

    I will try the later version of MPASM but I don't have PBP 2.50 - yet <grin>.

  19. #19


    Did you find this post helpful? Yes | No

    Default

    First thing I noticed. According to the MCP23016 data sheet, the control byte is 0100bbbx where bbb is the device address set on the address pins and x is where the read/write bit is located. *edit The address pins I am referring to are A0, A1, and A2 (pins 16,17 and 18 on the DIP package). So for a device with all the addres pins pulled low would have a control byte of $40, with all pins set high, the control byte would be $4E.

    Second you need to use the "define I2C_HOLD 1" because the MPC23016 pulls the clock low in order to signify it is not ready for the next byte of data.

    Thirdly the address field of the I2C commands should be where you put the register command byte for read or write of a register. The address field should be left out if you are reading the I/O status.

    Also are you using external 4.7k pullup resistors? The I2C commands set the SDA and SCL pins to tristate and only drive a low state. External pullups are needed unless you use "DEFINE I2C_SCLOUT 1" which defeats the clock hold capability of the MPC23016.
    Last edited by falingtrea; - 16th May 2008 at 19:44. Reason: added more info on address pins and pull up
    Tim Barr

  20. #20
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Confused but still no pins toggle

    Thanks for the input, I am confused however upon my reading (and re-reading the 23016 datasheet) writing to the config registers are:
    "First, the device is selected bt sending the slave address and setting the R/W bit to logic '0'. The command byte is sent after the address and determines which register will be written." and then it shows the waveforms for this.
    Address is sent 1st (according to the datasheet) and is 0-1-0-0-A2-A1-A0 and then the R/W bit. Next is the command byte (8 bits) and then the 2 data bits - Appaerntly this device uses 2 and accesses them automatically.

    All of this I think I get - but it still does not answer the fact that the data and clock pins do not toggle - AT ALL! I can see if I get my sequence wrong - but the lines should still toggle.

    Once I get the lines to at least toggle in some form, then I set myself to get the device to actually look like it may work.

    Any other ideas?

  21. #21
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Updated PBP now looking for MPASM 5.20

    Mr. E-
    I have updated to PBP 2.50 (we had it just not loaded) and am looking for MPASM 5.20 and don't seem to find it on Microchip's website - where did you find it?

    I re-compiled with PBP 2.50 and MPASM 5.14 and get the same thing - just dead pins.......

    I also added the patch so I am now using PBP 2.50A.....
    Last edited by ecoli-557; - 16th May 2008 at 20:32. Reason: edit

  22. #22
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ecoli-557 View Post
    I re-compiled with PBP 2.50 and MPASM 5.14 and get the same thing - just dead pins.......
    Wondering...how do you in fact know that the pins are actually dead...i.e. not doing anything?
    I know you said "by a scope" back in post #1...but what do you mean by 'scope'? A freq. meter, a 1Khz BW o-scope? A good o-scope with a decent bandwidth?
    I begin to wonder if in fact the pins are really doing something, but the method you are using to see said something is faulty...because any pulses coming out of I2CC/I2CD would probably be too fast to see with an ordinary meter.

  23. #23
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Troubleshooting gear

    Good thoughts, but, I am using a DSO with 100 MHz (not great but fast enough). And, remember (or not) I also remarked the coded for the I2C commands and added the same code used for the 'heartbeat' indication on an LED and watching the scope both lines followed the LED exactly. This should mean no sharts, the 23016 seems not to drag down the output of the PIC, etc.

    By rights it should work - I can not see why it won't. Regardless of the code issues, if the I2C command does anything it should 'wiggle' the pin and I am not seeing it. I have put the init section in its own loop and I still don't see any activity.

    My error label never gets activated so the proc thinks it is communicating with the 23016 but it is not.

    What else can I try? I appreciate the assist....

  24. #24
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=
    Also are you using external 4.7k pullup resistors? The I2C commands set the SDA and SCL pins to tristate and only drive a low state. External pullups are needed unless you use "DEFINE I2C_SCLOUT 1" which defeats the clock hold capability of the MPC23016.[/QUOTE]

    Yes, the data and clock lines are pulled up by a 4.7k resistor each. The 3 address lines are tied low.

  25. #25
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by falingtrea View Post
    First thing I noticed. According to the MCP23016 data sheet, the control byte is 0100bbbx where bbb is the device address set on the address pins and x is where the read/write bit is located. *edit The address pins I am referring to are A0, A1, and A2 (pins 16,17 and 18 on the DIP package). So for a device with all the addres pins pulled low would have a control byte of $40, with all pins set high, the control byte would be $4E.
    This is a bit murky for me, if the R/W bit is bit 0 in this sequence then it would be $40. If the bit does not figure into the sequence then it would add a 0 to the 8 bit position and it would be $20.

    I have tried both and the pins still do not toggle, thanks though.

  26. #26
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Fallingtrea update

    Quote Originally Posted by falingtrea View Post
    Second you need to use the "define I2C_HOLD 1" because the MPC23016 pulls the clock low in order to signify it is not ready for the next byte of data.
    When I added this to the code, it locks up at the init as I suspected it would as the proc sees nothing back from the 23016 due to the proc not sending anything to it.

  27. #27
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    100Mhz DSO should be fast enough...although if you're viewing the signals in real time, you still might not see the pulses. Maybe slow the clock WAY down (i.e. 32khz internal clock) and see if you can see anything. Maybe connect the pins to a pulse counter or a freq counter and see if that shows anything. Or a 555 timer set up as a one-shot pulse stretcher (i.e. 1us pulse gets stretched to 1 second so you can see it)...

    Have you tried connecting a plain ol' 24LC256 serial eeprom type thing to the PIC and working with that just for grins and see what happens? Then after that works, move back to the other chip?


    Quote Originally Posted by ecoli-557 View Post
    ........This should mean no sharts
    You said 'sharts'

  28. #28
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Well, Sharts!

    Well, oops <grin>, so much for engineers spelling......
    No, I have not tried a plain device, perhaps I should. I will try a few more desperate things before that this weekend.

    I will tie a logic probe to one of the pins and see what happens if anything.

    Thanks for the input. Any other ideas??

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


    Did you find this post helpful? Yes | No

    Default

    Seems i've overlooked this one..
    Code:
    @ __CONFIG _CONFIG4L, _LVP_ON_4L & _STVREN_ON_4L & _XINST_ON_4L & _DEBUG_OFF_4L
    Must be off as the compiler don't use the extended instruction set.

    DEFINE I2C_SLOW seems to do weird things here...

    EDIT: WHICH WILL BE FIX IF I DARE TO INSTALL THE LATEST PATCH
    * Adds support for PIC18F6628, 66J11, 66J16, 6723, 67J11, 8628, 86J11, 86J16, 8723 and 87J11.
    * Adds Microchip USB 1.2 fixes for PIC18.
    * Fixes USB for PIC18F87J50 series parts.
    * Sets Adcin default clock to rc for PIC16F882, 883, 884, 886 and 887.
    * Fixes Hpwm pin for PIC12F615, PIC12HV615, PIC16F616, 685, 690, 785, PIC16HV616 and 785.
    * Fixes Hserin2 timeout for PIC18.
    * Fixes I2C_SLOW Define for PIC18.
    * Fixes operator precedence in If..Then for long PIC18 (be safe - use parenthesis.)
    * Fixes Lookup2 for non-long PIC18.
    Last edited by mister_e; - 16th May 2008 at 23:18.
    Steve

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

  30. #30
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Seems i've overlooked this one..
    Code:
    @ __CONFIG _CONFIG4L, _LVP_ON_4L & _STVREN_ON_4L & _XINST_ON_4L & _DEBUG_OFF_4L
    Must be off as the compiler don't use the extended instruction set.

    DEFINE I2C_SLOW seems to do weird things here...

    EDIT: WHICH WILL BE FIX IF I DARE TO INSTALL THE LATEST PATCH
    Well now! We have made SOME progress here. Now the proc is upset that it has not heard back from the 23016! I did as Mr. E suggested and disabled the extended stuff in the proc.
    I am working at 20 MHz (tried going to 8 with no help Skimask), so now my LCD message of 'No ACK from I2C device' comes into play. Curious, but re-invigorated......

    I am also now using 2.50A PBP still have not located the MPASM 5.20........

    All comments and advice is needed however.......

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


    Did you find this post helpful? Yes | No

    Default

    Unfortunately, latest MPASM version comes with MPLAB on Microchip website.

    I never use PBP timeout for I2CWRITE... in case you REALLY want.. well, don't forget what i said... the timeout use a GOTO not a GOSUB. The way you did it, it assume a GOSUB.

    Also, use Variable in your I2CWRITE line, numeric value may screw things.
    Last edited by mister_e; - 16th May 2008 at 23:32.
    Steve

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

  32. #32
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Woo Hoo!

    Thanks to Mr. E's eagle eye, I think the disabling of the enhanced CPU did it! I just glossed right over it.
    My pins now reflect what I think they should - it still doesn't work - but at least it looks like we have made progress.

    Now that I have pins toggling, I now set my sight to the 23016 specifically. The datasheet is confusing and what I use to set it up:
    i2cwrite idata,iclock,$20,$06,[$00,$00],errori2c 'Sets both ports as OUTPUTS
    pause 20

    And to write to it:
    i2cwrite idata,iclock,$20,$00,[loop],errori2c
    pause 20

    may be wrong. According to what I get from the sheet it should be:
    address-command byte-data1-data2

    My address should be zero (0) as all address lines are at ground and command byte of $06 is IODIR0 and command byte $00 is access to GP0 (zero).

    Is this correct?

    -Starting to see some sky here

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


    Did you find this post helpful? Yes | No

    Default

    Try something like this
    Code:
            CONT con $20
            GP_Port con 0
            LAT_Port con 2
            IODir con 6
            Register var Byte
    
            Register=IODir        
            i2cwrite idata,iclock, CONT, register,[0,0] ' set all i/o to output
            
            Register=GP_Port 
            i2cwrite idata,iclock, CONT, register,[255,255] ' set all i/o to high
            
            Register=LAT_Port 
            i2cwrite idata,iclock, CONT, register,[255,255] ' set all i/o to high
    Steve

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

  34. #34
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Better.....

    OK, Thanks again to Mr. E, the data and clock pins are still working with the I2C commands - how interesting that the enhanced bit did that....

    The DEFINE I2C_SLOW 1 does not seem to make any difference in my test.

    icommand var byte 'The command byte to the MCP23016
    i2c_addr var byte 'Address of the 23016

    I set up the 23016 at address zero this way:
    i2c_addr=$20 'Address 0 for the test????
    icommand=6 'Access to IODIR0
    i2cwrite idata,iclock,i2c_addr,icommand,[$00,$00] 'Sets device as all OUTPUTS
    pause 20 'Cause its the thing to do
    (No error modifier Mr. E)

    Then I try to push the outputs low as I have 10k pullups on the outputs:
    i2c_addr=$20
    icommand=0
    i2cwrite idata,iclock,i2c_addr,icommand,[$00]
    pause 20

    The result is that all outputs are high, being pulled so by the 10k sip resistor.....

    Any thoughts?

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


    Did you find this post helpful? Yes | No

    Default

    This mean your device don't accept the first command, so all i/o are set to input, hence why the pull-up bring those pins to high.

    Try to install the PBP patch
    http://www.melabs.com/support/patches.htm

    or just comment the DEFINE I2C_SLOW... or both
    Steve

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

  36. #36
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Patches and more.....

    I have the patch installed and it is reported as 2.50a by Microcode Studio.

    I have put in this code based on what you posted:

    define I2C_SLOW
    'Constant list
    GP_port con 0
    LAT_port con 2
    IOdir con 6
    iaddr con $20
    'Variables
    ireg var byte
    'Set up the 23016
    ireg=IOdir
    i2cwrite idata,iclock,iaddr,ireg,[0,0] 'Sets GP0.0-GP0.7 as OUTPUTS
    pause 20
    'Write to the 23016
    ireg=GP_port
    i2cwrite idata,iclock,iaddr,ireg,[0,0]
    pause 20
    ireg=LAT_port
    i2cwrite idata,iclock,iaddr,ireg,[0,0]

    And the ports are all still high, I agree with you, the chip did not accept the first command.

    Did I understand your code?

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


    Did you find this post helpful? Yes | No

    Default

    What if you comment the DEFINE line?

    Would help if i had this chip here
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Could you attach the compiled .HEX file here (in a ZIP file), so i could see if the signal are correct?

    May worth to try to reduce those pull-ups from 4.7K to let's say 1.8 K
    Last edited by mister_e; - 17th May 2008 at 00:19.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default



    How about
    Code:
     iaddr CON $40
    Steve

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

  40. #40
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by falingtrea View Post
    Second you need to use the "define I2C_HOLD 1" because the MPC23016 pulls the clock low in order to signify it is not ready for the next byte of data.
    Fallingtrea and Mr. E (hey that rhymes!) have helped me see the problem.

    Mr. E noticed the enhanced bit set - this is REAL important - it screws stuff up. After that I actually had a waveform to look at. Then I noticed I wasn't getting ALL of my clock pulses only 3 chars worth. So I tried the DEFINE I2C_HOLD 1 from the book and Fallingtrea and that got all of my 4 chars of data clocked into the little sucker.

    Also, Fallingtrea was also correct in that a zero addressed part is address $40 and NOT $20 as I had thought - it didn't work before due to the enhanced CPU masking everything.

    I can now code myself into a corner and see how this thing really works.

    Thanks guys, I knew it was simple but what an ordeal! I will have a sip of Rye in both of your honor later <grin>.

    -Likin' coding once again!

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