Hi All,
I'm working on a project which uses Arduino Nano 3.0 connected to a MCP23S17 ( http://www.microchip.com/wwwproducts/en/MCP23S17 ). This is used for output only, and controls relays driven with ULN2803A chips. I have been able to make the MCP23S17 chip work using this method - Arduino DUE and MCP23S17 - software SPI and hardware SPI - Arduino Due - Arduino Forum , so I know it is wired correctly. But, I can't seem to get any output pins above 4 to behave correctly, so trying to use a library to make this work. My Chip Select is pin 18 (A4), and the MISO, MOSI, SCK are standard 11, 12 ,13. I want to be able to digitalWrite all pins 1-16 on the MCP23S17 as HIGH or LOW as it will ease my logic programming later - just trying to get the basic hardware control working for now. I'm using the library from Cort Buffington - Arduino Playground - MCP23S17 Class for Arduino. I have the latest V.2 which "Changed direct manipulation of pin 10 on ATMega168/328 via "PORTB" to use digitalWrite on an arbitrary SlaveSelect pin passed to the object through the constructor." Also using IDE 1.6.8.
Things I have tried;
Read through Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino - gained a little from this (only because my brain is not a programming type!) Mainly learned to watch for bring the SS Low to write to the MCP, then High to stop writing. From reading the MCP23S17.cpp file, I think that handles bringing the ss pin Low, writes the info to the specified pin, then returns the ss pin High.
Also have tried to change the SS pin in the pins_arduino.h file, even though this was not recommended. This did not work for me.
A simplified version of my sketch is below. Can anybody point out what I have missed or done wrong? I have been trying to get this working for a long time, and finally decided to ask for some help from those who are much more experienced at this!
#include <SPI.h>
#include <MCP23S17.h>
//const int MOSI = 12;
//const int MISO = 11;
//const int SCK = 13;
const int ss = 18;
const int address = 0;
MCP iochip(0, 18); // Instantiate an object called "iochip" on an MCP23S17 device at address 0
// and slave-select on Arduino pin 18
void setup() {
analogReference(EXTERNAL);
pinMode(8, OUTPUT);
digitalWrite(8, HIGH); //turn on main power relay
delay(2000); // wait for chip to stabilize
pinMode(10, OUTPUT); // keep this as output
iochip.begin();
digitalWrite(10, HIGH);
pinMode(ss, OUTPUT); //ss
//digitalWrite(_ss, HIGH);
pinMode(11, INPUT); //MISO
pinMode(12, OUTPUT); //MOSI
pinMode(13, OUTPUT); //SCK
iochip.pinMode(1, LOW); // Use bit-write mode to set the current pin to be an output
iochip.pinMode(3, LOW); // Use bit-write mode to set the current pin to be an output
//iochip.pinMode(0B0000000000000000); // set all MCP23S17 pins as output
iochip.byteWrite(IODIRB, 0x00); //Use byte-write to set all 8 bits of IO Direction register for portB to outputs
iochip.byteWrite(IODIRA, 0x00); //Use byte-write to set all 8 bits of IO Direction register for portA to outputs
}
void loop() {
digitalWrite(ss, HIGH);
//digitalWrite(ss, LOW);
iochip.digitalWrite(1, HIGH);
delay(500);
iochip.digitalWrite(3, HIGH);
delay(1000);
iochip.digitalWrite(1, LOW);
delay(500);
iochip.digitalWrite(3, LOW);
digitalWrite(ss, HIGH);
}
Thanks in advance for any pointers for me to look at!


