• PicŪ Basic


  • Port expansion using the MCP23S17-2

    The MCP23S17 device provides 16-bit, general purpose parallel I/O expansion for SPI bus applications.
    The MCP23S17 consists of multiple 8-bit configuration registers for input, output and polarity selection.

    The MCP23S17 SPI expander works the same way as the I2C model MCP23017. Please download and read the documentation of the MCP23017 and the MCP23S08.
    More documentation is available here: http://www.protonbasic.co.uk/content...-using-the-MCP.
    All code written by me in all the libraries expanders is based on Les Johnson's code.

    I present two libraries to use with the MCP23S17 SPI expander.
    The first library uses hardware MSSP module of the PIC(r). (immovable pins) (MCP23S17-H.inc)
    The second library uses software to create a dialogue on the SPI bus. (configurable pins) (MCP23S17-S.inc)
    In the file "MCP23S17-S.inc", 3 types of code can be used for software SPI communication.

    How to use the hardware library see the "MCP23S17-H" folder.
    How to use the software library see the "MCP23S17-S" folder.

    In the MCP23S17-H folder: Using the MSSP module of the PIC(r).
    Test_MCP23S17_16.BAS
    Testing the expander in inquiry mode with 16-bit commands because it is more efficient.

    In 8-bit mode:
    Test_MCP23S17_INT8-A.BAS
    Testing the expander in interrupt mode with INTCON bit = 0 (double interrupt) with 2 INT pins.
    Test_MCP23S17_INT8-C.BAS
    Testing the expander in interrupt mode with INTCON bit = 1 (single interrupt) with 2 INT pins.

    In 16-bit mode:
    Test_MCP23S17_INT16A.BAS
    Testing the expander in interrupt mode with INTCON bit = 0 (double interrupt) with 1 INT pin.
    Test_MCP23S17_INT16B.BAS
    Testing the expander in interrupt mode with INTCON bit = 0 (double interrupt) with 1 INT pin and less control code: with real speed.
    Test_MCP23S17_INT16C.BAS
    Testing the expander in interrupt mode with INTCON bit = 1 (single interrupt) with 1 INT pin.
    Test_MCP23S17_INT16D.BAS
    Testing the expander in interrupt mode with INTCON bit = 1 (single interrupt) with 1 INT pin and less control code: with real speed.

    In the MCP23S17-S folder: Using the I2C software. Same as above.

    CONCLUSION:
    The qualities and limitations are the same as the MCP23017 I2C expander.
    The MCP23S17 SPI expander is complicated, versatile and configurable.
    I hope this work will help to use the MCP23S17 more easily.
    Alberto Freixanet

    MCP23S17_library.zip