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

MCP23S08 doesn't work

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








MCP23S08 doesn't work
PostPosted: Fri Jan 27, 2006 12:50 pm     Reply with quote

Does anyone have a working code example for the MCP23S08 GPIO expander? I can't seem to find what is wrong with the code below. The expander chip never replies to anything sent to it. It's SDO pin stays low all the time. This device is like the MCP23S17 but it only has one I/O port.

//* write_gpio(int8 address, int8 data) subroutine ******************************
// address = register address
// data = data to place in register
// Initializes GPIO chip

void write_gpio(int8 address, int8 data) {

output_low(GPIO_CS);
spi_write(0x40); // Hardware address and R/W bit (bit 6 always on)
spi_write(address); // Register address
spi_write(data); // Data to send
output_high(GPIO_CS);

}
//******************************************************************************


//* read_gpio(int8 address) function *******************************************
// address = register address
// Returns: data from register
// Reads a value from the MCP23S08 GPIO expander

int8 read_gpio(int8 address) {

int8 data=0;
output_low(GPIO_CS);
spi_write(0x41); // Hardware address and R/W bit (bit 6 always on)
spi_write(address); // Register address
data=spi_read(0); // Read data in
output_high(GPIO_CS);
return(data);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 27, 2006 1:19 pm     Reply with quote

Post your setup_spi() statement. Also post your PIC type, #fuses
statement, and #use delay() statement.
Guest








PostPosted: Fri Jan 27, 2006 1:23 pm     Reply with quote

Here is the setup_spi statement and the first few lines of the source code.

#include "18f452.h"
#device ADC=10
#fuses HS, NOPUT, NOWDT, NOPROTECT, NOLVP, CCP2C1, NODEBUG, NOBROWNOUT
#use delay (clock=3686400)

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64);

I've played with the SPI clock quite a bit trying different values. Not that it should matter though since the MCP23S08 can run up to 10MHz and my crystal is only good for 3.6864MHz.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 27, 2006 1:47 pm     Reply with quote

Based on the Figure 2-5 (pg. 26) of the MCP23S08 data sheet, "SPI Input
Timing", it looks like data should be clocked out of the PIC on the negative edge of SCLK. This means you need to change the edge
parameter of setup_spi() to:
Code:
SPI_H_TO_L

That parameter controls which edge of SCLK is used to clock the data
out of the PIC.
Guest








PostPosted: Fri Jan 27, 2006 3:13 pm     Reply with quote

Thanks. I needed SPI_XMIT_L_TO_H as well, but you certainly got me going in the right direction. I'll post up what I have in the code library when I get this completed as a reference for anyone else who has problem(s) with this family of chips.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Jan 29, 2006 6:21 am     Reply with quote

The MCP23S08 has 10 Configuration and Control Registers that determine its behaviour.
You didn't show us how it was setted. To help you we need a complete and compilable
example code that demostrate the problem.


Humberto
lfander
Guest







PostPosted: Thu Jul 16, 2009 10:02 am     Reply with quote

What does this comment mean ???

spi_write(0x40); // Hardware address and R/W bit (bit 6 always on)

I've tried using this expander to light LEDs. Seven pins will sink current, but bit 6 will never will. Any ideas
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 16, 2009 1:28 pm     Reply with quote

Quote:

What does this comment mean ???
spi_write(0x40); // Hardware address and R/W bit (bit 6 always on)

When you're trying to understand a driver, it's essential to look at the
chip's data sheet. Download the mcp23s08 data sheet from this page:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en021817#1

Look at this bit diagram on page 8 of the mcp23s08 data sheet:
Quote:
FIGURE 1-3: SPI CONTROL BYTE FORMAT

It explains the comment in the code.
lfander
Guest







PostPosted: Thu Jul 16, 2009 2:14 pm     Reply with quote

I understand drivers and I did look at the data sheet first. Bit 6 is always high implies a hardware condition, not a "1" in the code sent to the device, thats why I asked. The pin controlled by bit 6 (GP6) is unresponsive when driven low as per Microchips app notes and data sheets, while the other pins do respond. That was my question.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 16, 2009 2:18 pm     Reply with quote

1. Post a short, compilable test program that shows the problem.
2. Post your compiler version.
3. Post a description of the external circuits connected to the GP6 pin.
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