Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define SCK 13
- //#define MOSI 11
- //#define MISO 12
- //#define SS 10
- #include <SPI.h>
- #define MCP23S17 B01000000 // MCP23017 SPI Address (Not used in this sketch)
- #define IOCON 0x0A // MCP23017 Config Reg.
- #define IODIRA 0x00 // MCP23017 address of I/O direction
- #define IODIRB 0x01 // MCP23017 1=input
- #define IPOLA 0x02 // MCP23017 address of I/O Polarity
- #define IPOLB 0x03 // MCP23017 1= Inverted
- #define GPIOA 0x12 // MCP23017 address of GP Value
- #define GPIOB 0x13 // MCP23017 address of GP Value
- #define GPINTENA 0x04 // MCP23017 IOC Enable
- #define GPINTENB 0x05 // MCP23017 IOC Enable
- #define INTCONA 0x08 // MCP23017 Interrupt Cont
- #define INTCONB 0x09 // MCP23017 1= compair to DEFVAL(A or B) 0= change
- #define DEFVALA 0x06 // MCP23017 IOC Default value
- #define DEFVALB 0x07 // MCP23017 if INTCONA set then INT. if diff.
- #define GPPUA 0x0C // MCP23017 Weak Pull-Ups
- #define GPPUB 0x0D // MCP23017 1= Pulled HIgh via internal 100k
- #define OLATA 0x14
- #define OLATB 0x15
- #define INTFA 0x0E
- #define INTFB 0x0F
- #define INTCAPA 0x10
- #define INTCAPB 0x11
- const int slaveSelectPin = 10; //アクティブLOW
- void setup() {
- // set the slaveSelectPin as an output:
- pinMode (slaveSelectPin, OUTPUT);
- // initialize SPI:
- SPI.begin();
- //IOCON設定(SEQOPのみDisable→0x20)
- writeData(IOCON,0x20);
- writeData(IOCON+1,0x20);
- //IODIRA,B設定(0で出力,1で入力)
- writeData(IODIRA,0x00);
- writeData(IODIRB,0x00);
- }
- void loop()
- {
- //GPIOB設定
- writeData(GPIOB,0xff);
- delay(300);
- writeData(GPIOB,0x00);
- delay(300);
- }
- void writeData(uint8_t addr,uint8_t data)
- {
- digitalWrite(slaveSelectPin,LOW);
- SPI.transfer(MCP23S17);
- SPI.transfer(addr);
- SPI.transfer(data);
- digitalWrite(slaveSelectPin,HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment