CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Heads up regarding MCP23S17 I/O expander

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

Heads up regarding MCP23S17 I/O expander
PostPosted: Tue Jul 04, 2006 2:55 pm     Reply with quote

I just spent a couple of hours troubleshooting a Microchip MCP23S17. Thought I'd pass this along for anyone else in the same boat as the data sheet for the device doesn't seem to be correct.

The data sheet states that the MCP23S17 will ignore its three external address pins (it will assume they're all 0) if the hardware enable (HAEN) bit in the io control (IOCON) register is cleared (0). This bit's default (power on/reset) state is 0. Turns out that even if HAEN is 0, it doesn't ignore these external address pins.

I have two MCP23S17's connected to one PIC. They share the same SPI_CLK, SPI_DIN, SPI_DOUT, /CS and /RESET lines. One has all external address lines pulled high, the other has them all pulled low.

Upon powerup, I was doing an initialization sequence. This consisted of pulling the /RESET line low to reset both io expanders simultaneously. Then I would write to the IOCON register to enable the HAEN bit. The way the datasheet is written, performing a write with a device opcode of 0x40 should simultaneously set both chips at once since they are supposed to powerup and ignore their address pins.

Using this initialization procedure, I was only able to initialize the MCP23S17 with its address lines pulled low. I now perform two initializations, one with an opcode of 0x40 (the io expander with 3 address lines low) and another with 0x4e (the io expander with 3 address lines high). Now both chips properly initialize.

Hope this helps someone.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Jul 04, 2006 6:13 pm     Reply with quote

Actually, according to the datasheet, the pins are NOT ignored when HAEN=0....

The fourth paragraph (column 2) on page 17 of the datasheet clarifies the issue. It says the pins must be biased even if the HAEN bit=0 which means they cannot be left floating, they must be pulled down to all 0's. So the device IS working properly according to the datasheet... but this is definitely something to watch for...

FWIW...
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Tue Jul 04, 2006 6:23 pm     Reply with quote

dyeatman wrote:
Actually, according to the datasheet, the pins are NOT ignored when HAEN=0....

The fourth paragraph (column 2) on page 17 of the datasheet clarifies the issue. It says the pins must be biased even if the HAEN bit=0 which means they cannot be left floating, they must be pulled down to all 0's. So the device IS working properly according to the datasheet... but this is definitely something to watch for...

FWIW...


The datasheet is somewhat ambiguous....

It does say that these pins must not be left floating if unused, but it doesn't say what they should be pulled to (high or low).

But from page 17 it clearly states that if enabled (HAEN = 1), the device's hardware address matches the address pins. If disabled (HAEN = 0), the device's hardware address is 0,0,0.

Whether that means that if HAEN = 0, the address lines MUST be pulled low is up for debate. I can vouch for the fact that regardless of the HAEN bit, the device's hardware address must match the address pins.

Like I said before, I hope this information prevents someone from chasing their tail for a few hours (unlike what I was doing earlier today).
Guest








PostPosted: Wed Nov 15, 2006 3:30 am     Reply with quote

Do you mind to share your codes in this forum?

If not, you can PM me so that I can pass my e-mail to you.

Thanks.

newguy wrote:
dyeatman wrote:
Actually, according to the datasheet, the pins are NOT ignored when HAEN=0....

The fourth paragraph (column 2) on page 17 of the datasheet clarifies the issue. It says the pins must be biased even if the HAEN bit=0 which means they cannot be left floating, they must be pulled down to all 0's. So the device IS working properly according to the datasheet... but this is definitely something to watch for...

FWIW...


The datasheet is somewhat ambiguous....

It does say that these pins must not be left floating if unused, but it doesn't say what they should be pulled to (high or low).

But from page 17 it clearly states that if enabled (HAEN = 1), the device's hardware address matches the address pins. If disabled (HAEN = 0), the device's hardware address is 0,0,0.

Whether that means that if HAEN = 0, the address lines MUST be pulled low is up for debate. I can vouch for the fact that regardless of the HAEN bit, the device's hardware address must match the address pins.

Like I said before, I hope this information prevents someone from chasing their tail for a few hours (unlike what I was doing earlier today).
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Nov 15, 2006 10:16 am     Reply with quote

Sorry, what I have developed is for a paying customer so I can't share it. However, what I do have was absolutely trivial to write. Just follow the datasheet and you'll do fine......keeping in mind the small issue I originally raised.
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 15, 2006 2:51 pm     Reply with quote

yes I find some data sheet can be somewhat confusing.

you can tell which data sheet were designed/written by university engineers Confused and data sheet designed/written for every day users. Very Happy

Wink Andrew
_________________
What has been learnt if you make the same mistake? Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group