need help with PBP, I2C and MCP23017


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108

    Default need help with PBP, I2C and MCP23017

    I've decided to abandon 5 months of learning C++ so I could use Arduinos and going back to the superior PBP and PIC MCUs. Having said that, Arduino had the most fantastic libraries which made I2C and MCP23017 (port expander), tremendously easy to use. I have code running that accesses 5 PE (port expander) equipped boards with 16 RGB LEDs each and able to access each individually with only a few commands.

    I'm now using my Lab X1, PBP, a single MCP23017 trying to light ONE LED. Yes, this is my Hello World experiment. I have the anode of a common anode RGB LED attached to portA.0, portC2 and portC3 connected to the port expander I2C connections. My R,G, B cathodes are connected to portA.0, porta.1 and porta.2 of the port expander.

    My program is attached. I'm using a logic probe to test pins, and get pulsing on the SDA and SCL lines. I get pulsing on the anode of the LED. On the 3 PE output lines I get a high pulse, that never goes low. Therein lies the problem...it has to go low since it's attached to the cathodes.

    I'm convinced it's more a configuration problem than hardware. I had the same setup for Arduino which worked fine.

    I stole some of the code from another writer and modified for my own use since I was just starting and didn't want to have to go through all the fuse parameters and other setup.

    Anyone out there have some insight into what's happening and how to fix? Once I get this hello world action going, I'll be homefree and be able to do all the other re-coding (from C++ to PBP).

    Code:
    #config
     __CONFIG _CONFIG1, _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF 
     __CONFIG _CONFIG2, _BOR40V & _WRT_OFF 
    #endconfig
    
    DEFINE OSC 20                   '20MHz crystal
    DEFINE I2C_SLOW 1 
    DEFINE I2C_SCLOUT 1
    
    ANSEL =     000000           'no analog, all digital!
    ANSELH =    000000
    TRISA =     000000           'all ports output
    TRISC =     000000
    
     
    SDA         VAR PORTC.4         'i2c data line   bob changed     needed pullup
    SCL         VAR PORTC.3         'i2c clock line  bob change
    led         var porta.0         'led for testing
    addr        var word           '
    
    
    INIT:
    I2CWRITE SDA,SCL,$20,[$05,%10111000]
    I2CWRITE SDA,SCL,$20,[$00,$00]
    addr = $00  
    
    MAIN:
        
        I2CWRITE SDA,SCL,$20,addr[$00]    
             
    gosub blink
    goto main
    
    blink:   
        led = 1     'blink led for feedback
        PAUSE 50
        led = 0
        pause 50
     return
    Last edited by queenidog; - 15th May 2018 at 15:53. Reason: code cleaned up

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: need help with PBP, I2C and MCP23017

    It's probably your copy and paste, because it's done it to me before on this forum, but if the code is indeed correct, your ANSEL, ANSELH, TRISC, and TRISA don't look right. It should a % sign letting PBP know that it's binary and it should have 8 bits.

    TRISC = %00000000

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,512


    Did you find this post helpful? Yes | No

    Default Re: need help with PBP, I2C and MCP23017

    I2CWRITE SDA,SCL,$20,[$05,%10111000]

    I had the same setup for Arduino which worked fine.
    Arduino use a 7 bit i2c address pbp uses a 8 bit address.
    you make no mention of how you have AO,A1,A2 on the expander connected

    pbp i2c address = (% 0 1 0 0 A2 A1 A0 )<<1 for a mcp23017
    Warning I'm not a teacher

  4. #4
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: need help with PBP, I2C and MCP23017

    Address bits are connected to ground. for Arduino I could use address $20 or 0 to access, the latter if I used one of the libraries.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,512


    Did you find this post helpful? Yes | No

    Default Re: need help with PBP, I2C and MCP23017

    for Arduino I could use address $20 or 0 to access, the latter if I used one of the libraries.
    in Australia I drive on the other side of the road, its horses for courses
    pbp uses 8bit address scheme



    Address bits are connected to ground
    so A0=0 A1=0 A2=0
    plugged into formula
    pbp i2c address = (% 0 1 0 0 A2 A1 A0 )<<1
    addr =(%0100000)<<1 = $40

    so
    I2CWRITE SDA,SCL,$40,[$05,%10111000] is whats required
    Warning I'm not a teacher

  6. #6
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: need help with PBP, I2C and MCP23017

    Thanks Richard. MELabs also told me it was $40 for address. That was the problem! That and the fact my outputs are active low and I was sending active high bits.

Similar Threads

  1. I2C question w/ MCP23017 Port Expanders
    By dsicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th December 2012, 06:47
  2. PIC 18F4550 and MCP23017
    By DaveC3 in forum Code Examples
    Replies: 12
    Last Post: - 4th December 2010, 15:01
  3. HW I2C with PBP
    By EToscano in forum Serial
    Replies: 0
    Last Post: - 15th October 2009, 18:35
  4. i2c PBP questions
    By TimV in forum General
    Replies: 14
    Last Post: - 5th February 2007, 18:58
  5. More I2C question with PBP
    By Qacer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd March 2006, 22:35

Members who have read this thread : 2

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

Tags for this Thread

Posting Permissions

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