MCP23S17 Test

Dependencies:   MCP23S17 mbed mbed-rtos

main.cpp

Committer:
ryood
Date:
2016-10-28
Revision:
2:c8c30a78bbb3
Parent:
1:5321e8f5b339
Child:
3:42a3ae578926

File content as of revision 2:c8c30a78bbb3:

/*
 * MCP23S17 Test
 *
 * https://developer.mbed.org/users/romilly/code/MCP23S17/
 *
 * mbed:  rev 121
 * mbed-rtos: rev 117
 *
 * Created: 2016.10.28
 *
 */

#include "mbed.h"
#include "rtos.h"
#include "MCP23S17.h"

#define OPCODE (0x40)

SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk
//SPI Spi(PA_7, PA_6, PA_5); // SPI1:  mosi, miso, sclk

// MCP23S17(SPI& spi, PinName ncs, char writeOpcode);
MCP23S17 Mcp23s17(Spi, PD_2, OPCODE);

int main()
{
    printf("\r\n\n*** MCP23S17 Test ***\r\n");

    // PORTA output
    Mcp23s17.direction(PORT_A, 0x00);

    // PORTB input
    Mcp23s17.direction(PORT_B, 0xFF);
    // PORTB pull-up
    Mcp23s17.configurePullUps(PORT_B, 0xFF);
    
    // LED Check
    for (int i = 0; i < 8; i++) {
        Mcp23s17.write(PORT_A, (1 << i));
        wait(0.2);
    }
    Mcp23s17.write(PORT_A, 0x00);
    
    while (true) {
        char data = ~Mcp23s17.read(PORT_B);
        Mcp23s17.write(PORT_A, data);
        
        //printf("%02x\r\n", data);
    }
}