Shop OBEX P1 Docs P2 Docs Learn Events
problems coding for MCP23016 expansion chip — Parallax Forums

problems coding for MCP23016 expansion chip

verobelverobel Posts: 81
edited 2007-10-23 21:17 in General Discussion
Fellow SXers;
Some questions and code for you to look at...

I have been working on the SX/28 and some I2C chips. (So far: 24LC64 memory, DS1621 temp; and now MCP23016 expander) on the PDB board. Display is to a 2 Digit 7 segment LCD using RB and RC outputs. The display, temperature and memory have all been working and my latest addition is the expander chip. I now get compiler warnings & error

1) warning 37, pass 2: literal truncated to 8 bits
·· line MOV# __PARAM1,#wr23016··· ;I2CSEND, wr23016
2) error 43, pass 2: address exceeds memory limit
· .. I have tried commenting out portions of code..eg MEM_IN.. but still fall short

·Is item 1 important?
·Does item 2 mean my program is too big...and what to do about it?
·How does the setup code and then EXP_IN, EXP_OUT code look for the MCP23016?

·Thanks, John

Comments

  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-10-20 02:00
    You have a LOT of SX/B I2C commands, and every one of them gets compiled in place and consumes program memory. You can encapsulate these commands in subroutines/functions to get what you need without chewing up all of your flash. See my EEPROM example in this thread: http://forums.parallax.com/showthread.php?p=683617
  • BeanBean Posts: 8,129
    edited 2007-10-20 12:38
    I assume this line:

    DevType CON $0100 << 4 'Device type

    Should be:

    DevType CON %0100 << 4 'Device type

    Note a "%" instead of a "$"

    Even if you do fix this line, you are still out of code space. Use the techniques that Jon has suggested. Then you will have lots of code space left.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • verobelverobel Posts: 81
    edited 2007-10-21 00:04
    *Thank you* gentlemen for your suggestions

    I fixed the error above and stripped the program down to MCP23016 only code...
    no more memory error. I will address Jon's suggestion to encapsulate code
    in subroutines to avoid too much inline stuff.. later.

    The lateset program is attached in file EXP1I2.SXB. It doesn't put anything
    out on the display yet.. if I get a high on GP0.x it should work since doing
    it manually with a wire..lights up a segment on the display.

    I have some concern over the exterior capacitor 33 pf· and resistor 3.9k.
    The resistor is spot on but I'm uncertain of the capacitor value is is identified
    with ( green 102M 1KV 250) .. I'm thinking it might be 250 pf. Meter says 2.1 nF..but
    I'm not sure if it goes down that far. It may be another day or 2 before I can try
    to get 33 pf at RadioShack. In the mean time do you think this one would work?

    Any comments on latest source would also be appreciated..

    ·EXP_OUT:
    · tmpB1 = __PARAM1··' digit to display
    · I2CSTART SDA
    · I2CSEND SDA, Wr23016··' send to who
    · 'I2CSEND SDA, GP0··' info for register·· .. would not compile, replace below
    · I2CSEND SDA, $00··' info for register
    · I2CSEND SDA, tmpB1··' the data to send
    · I2CSTOP SDA
    · PAUSE 100
    · RETURN

    'I2CIN SDA, Rd23016, GP1, butCtrl
    ·EXP_IN:
    · I2CSTART SDA
    · I2CSEND SDA, Wr23016··' send to who
    · I2CSEND SDA, GP1··' info for register
    · I2CSTART SDA
    · I2CSEND SDA, Rd23016··' receive from who
    · I2CRECV SDA, tmpB2, Nak·' receive byte
    · I2CSTOP SDA
    · PAUSE 100
    · RETURN tmpB2

    Thanks, John
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-10-21 04:01
    102M

    10 followed by two zeros, pF --> 1000 pF ("1nF")
  • verobelverobel Posts: 81
    edited 2007-10-23 18:51
    I was able to get a 68pf capacitor. My nexxtech meter reads .07 nF .. I thinks its at its minimum measurement range.. I finally found the manual for it... need to press the 'REL' button before taking measurement this small..

    Unfortunately, program still not working.
  • verobelverobel Posts: 81
    edited 2007-10-23 20:13
    Hi all.. what a difference a couple days off makes... willing to recheck circuit and code.. find problem
    Had wiring error mixup pin 19 vs 18... circuit now diplaying on 2 LED's, one direct from SX/28 the other thru MCP23016.

    Currently have 1 question:

    1) I currently have code to increment a counter:· from 1 to 16 but it doesn't seem to work. What is wrong?
    ·· IF countB = 16 THEN
    ······ countB = 0
    ······ ELSE
    ······ countB = countB + 1
    ······ ENDIF
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-10-23 20:21
    Here's a slightly more elegant way to keep your value between 0 and 15:

    INC countB
    countB = countB & $0F
    
  • verobelverobel Posts: 81
    edited 2007-10-23 21:13
    My code was ok.. I was just misInterpreting the result. I like your masking idea though.
    One other question... is there some way to speed up the program download ..it currently takes me about 30 seconds.
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-10-23 21:17
    No, the download speed is what it is -- the only way to reduce the download time is to shrink the size of your program; you can do that -- as I suggested in another post -- by encapsulating the I2C commands in subroutines, that way they only compile once and will significantly reduce your program size.
Sign In or Register to comment.