Shop OBEX P1 Docs P2 Docs Learn Events
MCP23S17 and an LCD Display — Parallax Forums

MCP23S17 and an LCD Display

G McMurryG McMurry Posts: 134
edited 2010-01-25 00:17 in BASIC Stamp
This forum is fantastic.

I have solved so many problems with a quick question here. I thought I would give this one a try.

I have an application similar to the Nuts & Volts EXPANSION MADE EASY Column #109. I was able to find someone selling a nice 2X16 LCD Display that has a MCP23S17 as an interface. For my application, I need to conserve all the IO I can with my BS2p (or maybe a BS2). Therefore the idea of only using three IO pins seemed good.

I found the Nuts & Volts article Column #109 called Expansion Made Easy but it uses an MCP23016. I thought for sure I would be able to find some sample code using the MCP23s17 but so far no luck.

Can anyone help me here?

THANKS

Greg

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
AUTOMATE EVERYTHING
http://www.trainyard.net

Comments

  • G McMurryG McMurry Posts: 134
    edited 2010-01-24 15:16
    OK I'm not getting anywhere with my first question. Maybe I can just find someone here that has used the Microchip MCP23S17 in a Basic Stamp project. FORGET THE LCD PART. I am sure I can figure that part out.

    I just can't seem to get the thing running at all. I need help understanding the initialization.

    It would seem this would be a popular product. 16 I/O bits for under $2.00

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-24 15:55
    The MCP23S17 works like the MCP23017 which is an improved version of the MCP23016 except that the MCP23S17 uses the SPI protocol rather than the I2C protocol. You pretty much use the same commands, status, etc. except the communications with the MCP23S17 is done using the SHIFTIN and SHIFTOUT statements rather than the I2CIN and I2COUT statements described in the Nuts and Volts article. SPI also requires 3 or 4 I/O pins rather than the 2 I/O pins used with I2C. The MCP23S17 can have SI and SO connected together. I'd put a 470 Ohm resistor between the Stamp I/O pin and SI/SO. Make sure you read the datasheet for the MCP23017/MCP23S17.
  • G McMurryG McMurry Posts: 134
    edited 2010-01-24 16:18
    Thanks Mike,

    I am not even trying to READ the MCP23S17 yet. No connection there... I will go back and look at the Nut's N Volts article again. It seemed to me that the difference between the two devices was considerably different.

    I have a simple wiring... A0-A2 gounded. R/C on the reset pin (it resets every time it gets turned on. I have control over /CS, SCK and SI.

    My first experiments, all I want to do is set GPA0-7 as outputs and write to them.

    It is my understanding that each instruction takes 3 bytes. Opcode / Register / Data

    My first assumption was that all I would need to do was the following:

    Upon reset, the MCP23S17 comes up IOCON BANK=1 I use addresses for Bank=1

    OpCode $41
    IOCON $05 turn off sequential operation
    Data $40

    OpCode $41
    IODIRA $00
    Data $00 make port A output

    OpCode $41
    OLATA $0A
    Data $55 send outputlatch for port a 01010101 $55 (an easy to see value on a row of leds connected to GPIOA



    Here is my SPI Sub-Routine in PBasic

    delaytime = 10




    write_MCP:
    FOR index = 7 TO 0
    IF index < 8 THEN Put_Digits
    GOTO noop1
    Put_Digits:
    LOW CS
    PAUSE Delaytime
    SHIFTOUT SI, SCK, MSBFIRST, [noparse][[/noparse]mcp_data]
    PAUSE Delaytime
    HIGH CS
    NEXT
    noop1:
    RETURN

    PS Thanks for your terrific help in programming my MAX7219 Display Driver.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-24 16:46
    First of all, a write cycle uses address byte $40. According to the datasheet, the BANK bit is zero on a reset.

    LOW CS
    SHIFTOUT SI,SCK,MSBFIRST,[noparse][[/noparse]$40,$00,$00] ' make port A outputs
    HIGH CS
    LOW CS
    SHIFTOUT SI,SCK,MSBFIRST,[noparse][[/noparse]$40,$14,$55] ' set port A output latches to $55
    HIGH CS
  • G McMurryG McMurry Posts: 134
    edited 2010-01-24 17:08
    Just as you wrote, I was finding out that all my for/next is not necessary. Just had to read more carefully... (ha)

    I am now getting something though not exactly what I expected. But enough for me to poke at. I thought that we would need to set the OpCode byte to $41 to set the R/W bit to W but I see the error in my thinking there. AND I was over thinking the BANK issue. Of course you are correct...

    I will mess with this some more. Again, thanks for your help.

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-24 18:08
    @Greg - Have fun figuring this out. Reading carefully often gets you a huge amount of information for your efforts. I recommend it. I've not actually used an MCP23017 or MCP23S17, but I've read through the datasheet several times in the past when I was looking at I/O expanders. I just pulled it up on the internet when answering your questions and skimmed through it looking for relevant information.
  • G McMurryG McMurry Posts: 134
    edited 2010-01-25 00:17
    Working fine now. I was just a little overwhelmed by all the options.

    Now on with the LCD... (grin)

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
Sign In or Register to comment.