Author Topic: Resetting MCP23S17  (Read 2350 times)

0 Members and 1 Guest are viewing this topic.

Offline mheruianTopic starter

  • Contributor
  • Posts: 43
  • Country: ph
Resetting MCP23S17
« on: December 20, 2018, 06:15:30 pm »
Hi Great Ones :D

Sorry 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 help :(

PS: 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: [Select]
#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 Output
  digitalWrite(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[i]);
          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 = "";
   
  }
}
 

Offline CJay

  • Super Contributor
  • ***
  • Posts: 4136
  • Country: gb
Re: Resetting MCP23S17
« Reply #1 on: December 20, 2018, 07:18:30 pm »
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?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12863
Re: Resetting MCP23S17
« Reply #2 on: December 20, 2018, 07:34:02 pm »
Also its possible that AVR GCC is optimising the calls to digitalWrite() in:
Code: [Select]
    } 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: [Select]
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.
« Last Edit: December 20, 2018, 07:36:30 pm by Ian.M »
 

Offline viperidae

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: nz
Re: Resetting MCP23S17
« Reply #3 on: December 21, 2018, 07:12:56 am »
Number One rule, thou shalt measure voltages.

Get out your multimeter and measure the voltage on the reset pin.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: Resetting MCP23S17
« Reply #4 on: December 21, 2018, 11:08:35 am »
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.
 

Offline CJay

  • Super Contributor
  • ***
  • Posts: 4136
  • Country: gb
Re: Resetting MCP23S17
« Reply #5 on: December 21, 2018, 03:26:34 pm »
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.

Ah 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!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf