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

Help getting MCP23S17 outputs work

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



Joined: 29 Dec 2006
Posts: 2

View user's profile Send private message

Help getting MCP23S17 outputs work
PostPosted: Sun Dec 31, 2006 10:04 pm     Reply with quote

I have programmed MCP23S17 for GPA and GPB as outputs from PIC18F4550. MCP23S17 outputs are randomly blinking, but not the way as expected.

Code posted below:

I feel Problem may either be
- with configuring MCP23S17 GPIO, IOCON registers
- with MCP23S17 initialization function
- with write to MCP23S17 function


Can anyone help me in this please ..?

Appreciate the interaction

________________
////addresses in 8 bit mode: All addresses are based on page 5 & bank 0 of PIC18F4550
#define MCP23S17_IOCON0_address 0x0A ////used to configure banks
#define MCP23S17_IOCON1_address 0x0B

#define MCP23S17_IODIR0_address 0x00 ////used to set directions of individual bits on ports
#define MCP23S17_IODIR1_address 0x01

#define MCP23S17_GPIO0_address 0x12 ////write to these registers to write to the port
#define MCP23S17_GPIO1_address 0x13





void init_MCP23S17(unsigned char MCP23S17_device_address)
{
////us_delay_MCP2317(750); //// wait for expander to power up
NF_PIC18F4550_init_SDO(); ////PIC18F4550: clear TRISC<7> & initialize SDO
NF_PIC18F4550_init_SCK_M_mode() ////PIC18F4550: clear TRISB<1> to select Master mode
NF_PIC18F4550_init_CS(); ////PIC18F4550: clear TRISA<4> to initialize CS as output
NF_PIC18F4550_CS_disable(); ////PIC18F4550: disable CS of
OpenSPI(SPI_FOSC_64, MODE_00, SMPEND); ////Open SPI mode 00mid 00end_w 11MID_no 11end_no

////now set up the selected IO expander registers (IODIR, CONFIG, IPOL input polarity, OLAT etc)
write_to_MCP23S17(MCP23S17_IOCON0_address,0xA0); //configure IOCON register as separate banks sequential o/p mode disabled
write_to_MCP23S17(MCP23S17_IODIR0_address,0x00); //configure IODIRA as output
////write_to_MCP23S17(MCP23S17_GPIO0_address,0X00); //write some value to lower port


write_to_MCP23S17(MCP23S17_IOCON1_address,0xA0); //configure IOCON register as separate banks sequential o/p mode disabled
write_to_MCP23S17(MCP23S17_IODIR1_address,0x00); //configure IODIRA as output
////write_to_MCP23S17(MCP23S17_GPIO1_address,0X00); //write some value to lower port


}//// finished the function:


////
void write_to_MCP23S17(unsigned char writeAddress, unsigned char data)
{
NF_PIC18F4550_CS_enable(); Delay1TCY();
WriteSPI(MCP23S17_SPI_writeCmd); Delay1TCY();
WriteSPI(writeAddress); Delay1TCY();
WriteSPI(data);
NF_PIC18F4550_CS_disable();
}
//// finished the function:
dyeatman



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

View user's profile Send private message

Try the proper forum
PostPosted: Mon Jan 01, 2007 8:44 am     Reply with quote

In your earlier post you indicated you were looking for help with a C18 coding problem. Please look at the header for this forum and you will see it is CCS C NOT Microchip C18. The reason you are not getting responses is because you are in the wrong forum.

Try going here to see if you get the help you need:
http://forum.microchip.com/tt.aspx?forumid=3
Guest








PostPosted: Mon Jan 01, 2007 5:51 pm     Reply with quote

Thank you dyeatman !
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