Resetting MCP23S17 - Page 1
Forum section: electronics / beginners

author: mheruian
author_rank: Contributor
timestamp: December 20, 2018, 06:15:30 pm
content: Hi Great OnesSorry if this may sound trivial but i had it already, been done searching and doing stuffs but I'm unable to properly reset programmatically the MCP23S17, so my setup is just simple, arduino uno having SPI lines connected properly to the MCP23S17, connected hardware addresses pins all to ground and reset pin to vcc. I had successfully controlled it as an ouput expander (on leds) w/o library, just simple SPI transaction of opcode -> register address -> data (ofc, done some spi initial setups like spi parameters, etc.)Now i wanted to reset it programmatically after doing some output states on leds, now searched out on how other chips are being reset specially this is chip has a low-enable reset like on atmega328 so for me to reset it, i simply put a pull up resistor to the reset pin where as it still functions great but then whenever i try to put or input a logic low / gnd after pull up resistor (as image below), the chip resets but unable to operate again unless i restart my arduino uno, why is that?tried to search a lot of forum, on its datasheet even its libraries but nothing mention on how to reset the chip externally via programmatically controlled input on it. Please helpPS: my arduino code i use. (it's just a simple serial input via keyboard on the serial monitor which logic and operation works fine not until i tried to connect the pin to the mcp23s17's reset to actually sent out signal low)Code:#include <SPI.h>uint8_t leds[] = {0x01, 0x02};//, 0x04};//, 0x08};int cs = 10;int reset = 8;String cmd = "";SPISettings spi(SPI_CLOCK_DIV2, MSBFIRST, SPI_MODE0);void setup() {Serial.begin(9600);SPI.begin();pinMode(cs, OUTPUT);pinMode(reset, OUTPUT);SPI.beginTransaction(spi); //DISABLE SEQOP (Sequential Operation)digitalWrite(cs, LOW);SPI.transfer(0x40);SPI.transfer(0x05);SPI.transfer(0x20);digitalWrite(cs, HIGH);SPI.endTransaction();SPI.beginTransaction(spi); //Configure I/O Direction to OutputdigitalWrite(cs, LOW);SPI.transfer(0x40);SPI.transfer(0x00);SPI.transfer(0x00);digitalWrite(cs, HIGH);SPI.endTransaction();SPI.beginTransaction(spi); //reflects the same logic state of the input pin.digitalWrite(cs, LOW);SPI.transfer(0x40);SPI.transfer(0x01);SPI.transfer(0x00);digitalWrite(cs, HIGH);SPI.endTransaction();digitalWrite(cs, HIGH);digitalWrite(reset, HIGH);Serial.println("Start");}void loop() {if (Serial.available() != 0) {while (Serial.available() != 0) {char c = Serial.read();cmd += c;delay(1);}Serial.println(cmd);if (cmd.equals("1")) {for (int c = 0; c < 3; c++) {for (int i = 0; i < sizeof(leds); i++) {SPI.beginTransaction(spi);digitalWrite(cs, LOW);SPI.transfer(0x40);SPI.transfer(0x13);SPI.transfer(leds);digitalWrite(cs, HIGH);SPI.endTransaction();delay(500);}}} else if (cmd.equals("0")) {digitalWrite(reset, LOW);digitalWrite(reset, HIGH);Serial.println("This is successfully printed upon input 0 at serial monitor");}cmd = "";}}

author: CJay
author_rank: Super Contributor
timestamp: December 20, 2018, 07:18:30 pm
content: Bluesky thinking as I don't know for definite but I wonder if SPI.h is using hardware SPI on the ATMega and the SPI module is left hanging when you reset the I/O Expander...Maybe try closing SPI in code with SPI.end () before you initiate the MCP23S17 reset?

author: Ian.M
author_rank: Super Contributor
timestamp: December 20, 2018, 07:34:02 pm
content: Also its possible that AVR GCC is optimising the calls to digitalWrite() in:Code:} else if (cmd.equals("0")) {digitalWrite(reset, LOW);digitalWrite(reset, HIGH);Serial.println("This is successfully printed upon input 0 at serial monitor");well enough that on a 16MHz Arduino its violating the 1us minimum reset low time spec. in the MCP23S17 datasheet.Try adding:Code:delayMicroseconds(5);after each digitalWrite() to the reset pin in this section of your code to guarantee a long enough reset pulse and allow some time for the MCP23S17 to initialise after it goes back high.

author: viperidae
author_rank: Frequent Contributor
timestamp: December 21, 2018, 07:12:56 am
content: Number One rule, thou shalt measure voltages.Get out your multimeter and measure the voltage on the reset pin.

author: mikerj
author_rank: Super Contributor
timestamp: December 21, 2018, 11:08:35 am
content: After a reset you will need to reconfigure all the registers in the device. Calling the setup() function after the reset pulse should do the trick.

author: CJay
author_rank: Super Contributor
timestamp: December 21, 2018, 03:26:34 pm
content: Quote from: mikerj on December 21, 2018, 11:08:35 amAh now that's an obvious and very good point, it won't retain the configuration after a reset and default config is for all ports set as inputs!