Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to init multiple MCP23S17 ?

Status
Not open for further replies.

crocu

Member
Hello

I need to address 3 x MCP23S17.

The 1st chip has hardware address : 000
The 2sd chip has hardware address : 001
The 3rd chip has hardware address : 111

I've tried to configure IOCON register in order to set HAEN bit accordingly.

Into my init function i think i have to enable the hardware address for the 3 chips.

In order to do that,
Should i configure IOCON register only one time by setting the device hardware address as 000 ?
Then*all of the 3 chips will receive the same IOCON configuration with HAEN set ?

OR

I should write 3 x IOCON configurations : one for each chip by specifying the device hardware address into the control byte of the chip i'm talking to ?
( datasheed page 8, fig 1-3 )

I did not find in the datasheed how to proceed in order to init multiple MCP23S17 with hardware address enabled.

Many thanks for your help,
 
Last edited:
Yes i need to save pins, my hardware has been set to use only one CS pin for 3 MCP23S17 chips.

These chips offer the possibility to hardware address them, I need help to init the chips in order to work in that configuration.

Best regards,
 
Then I not really sure... Seeing as the HAEN bit is 0 by default, you may only need to write to that address once and set the bit.. That should set the bits in all three, then you'll have to access then by address..... ( you obviously need to be able to do this, as there would be no need for address pins )
 
I'm not sure to have well understood how you would proceed,

HAEN is a bit not of IOCON register and it is indeed set to 0 as default.

Because my 3 chip are hardware addressed I do not know if the Opcode to be sent to the IOCON register should contain 000 as A0,A1,A2 address or not for the init sequence.
 
Until you set the HAEN in each chip they are all addressable on the same address.... So if you write to the IOCON register(0x15) with 0x8. it will write to all three chips as they are all at the same address... Once the bit has been set they will all be on their separate addresses...
 
Ok, so i should send 3 x IOCON configurations, one of each chip in order to enable HAEN bit on each.

By default, bit 7 of IOCON register is set to 0.
So IOCON register is in 16 bit mode at the chip start-up [seen in Datasheet page 18], this should mean IOCON register address is 0x0A or 0xB (not 0x15) shouldn' t it ?

Then if the hardware addresses of my chips are 000, 001 and 111
Do you confirm i have to send 3 differents IOCON configuration like this ?


Code:
void WriteReg_MCP23S17(unsigned char HardwareAddr, unsigned char RegAddr, unsigned char RegValue);

// Writes IOCON register configuration :
// BANK=0 : IOCON addresses are page 11
// MIRROR=1 : Int pins internally coonected, SEQOP=1 : Sequential operation disabled
// HAEN = 1 : Hardware address DISABLED, INTPOL = 1 : Int ouptput pin is active high

// Configuration for the chip Hardware addressed : 000
WriteReg_MCP23S17(0,0x0B,0b01101010);		
// Configuration for the chip Hardware addressed : 001
WriteReg_MCP23S17(1,0x0B,0b01101010);

// Configuration for the chip Hardware addressed : 111
WriteReg_MCP23S17(7,0x0B,0b01101010);
 
Do you confirm i need to init each chip as i did in my previous post,

One IOCON register configuration for each chip ?
 
I think, Like I said in a previous post (I'm not sure ), that just having all three connected to sdi, sdo, cs and clock... if you write to internal address 05h or 15h, with the two bytes you need (MIRROR and HAEN) ALL three chips will read the in coming data... As its a write it should be okay... My only concern is a bus collision on the SDI pin on the micro as all three will respond at the same time...

Maybe you need to install the chips one at a time...
 
I hope I can help here. I am already using 40 MCP23S17 chips on one SPI bus, using just 5 CS lines, each shared by 8 MCP23S17 chips addressed as 0-7

Ian is correct, the first command you should send with CS low is to enable HAEN. On power-up this is disabled, so the hardware addresses of your 3 chips will be ignored, and they will ALL see the and react to the HAEN. After that you can (and must) use the appropriate address.

There is a "gotcha" though. The higher-order addresses (4-7) will not react to the HAEN which has its address set as a low-order adress (I use 0). For this reason, you must send 2 HEAN commands at first. They are identical, except that the first has address 0, and the second has address 4. This is really important, because otherwise your chip at address 7 will respond to all the commands sent on the SPI bus whether for itself of one of the other chips.
 
After that, during initialisation I then (for each chip addressed individually) set the pull-ups on, input_polarity on (because of how my particular hardware works), and data-direction as needed (I have a combination of inputs and outputs, some mixed on individual chips).

After that, I've finished with initialisation and I loop round the chip-selects, loop around the addresses and read/write as necessary.


Writing this, I realise that I could have set the pull-ups and input-polarity on BEFORE setting the HAEN because all chips would respond. I'm not sure about how this would be affected by the bug with the high-order address bit though. Also, I could have done this to all 5 banks simultaneously if I had set all the CS lines low at the same time. I didn't, and I won't be changing this now. Initialisation happens once at power-up, and its pretty quick.

Good luck.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top