MCP23S17 - wasn't working, started working, stopped working!

Hi there,

My apologies if this has already been covered, but I seemed to notice a very odd thing when using the MCP23S17 with the Arduino.

Just to let you know, I am using the MCP23S17 library with it, and not plain SPI commands. I will use those next if this doesn't work as planned.

Basically, I was trying to talk to the MCP23S17, and it wasn't working. I have three LEDs wired to pins GPB5,6 and 7, or pins 14,15 and 16 according to the library.

I had the following code:

#include <SPI.h>
#include <MCP23S17.h>
#include <LiquidCrystal.h>

MCP onechip(0);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
	
	  lcd.begin(20, 4);
  lcd.print("Hello");
  // Initialize SPI to talk to the DAC
  SPI.begin(); 
	pinMode(6,OUTPUT);
	onechip.pinMode(15,LOW);
	

}

void loop()
{
		digitalWrite(6, LOW);
	onechip.digitalWrite(15,HIGH);
	digitalWrite(13,HIGH);
	delay(1000);
	onechip.digitalWrite(15,LOW);
	digitalWrite(13,LOW);
	delay(1000);
	digitalWrite(6,HIGH);
	
}

Originally the code wasn't working, but somehow it started to work, and I started to get my LEDs to blink as I wanted.

However, I noticed that with each new programming exercise, the LEDs started to get dimmer and dimmer. Till the whole system stopped working altogether.

Basically I have three LEDs as outputs and rest are inputs, which are buttons that are pulled up by default and get pulled to zero when pressed. I hadn't gone as far as testing those properly.

I do not have my scope with me right now (joys of working between two sites), but I will definitely probe it with a scope to see what is going on.

Overall, I can think of two obvious problems:

  • I killed the MCP23S17 somehow
  • The library has some issues and doesn't work the same way every time

I am hoping the solution is a bit more obvious, as if in adjusting my code I have done something silly which I cannot see (too close to the problem).

The final code that I have in my setup is above.

Any help, or anybody with experience on the MCP23S17, your feedback would be appreciated.

Just to add, I kept it off for an hour or so, and now the code that wasn't working is working again...

I can't see any obvious signs of overheating on the system.

This leads me to believe the following:

  • A dodgy chip - me being unlucky?
  • SPI bus on the Arduino Micro not working as hoped/expected
  • Some cheeky speck/fleck passed over the board shorting something out.