sandeepvd
Joined: 29 Dec 2006 Posts: 2
|
Help getting MCP23S17 outputs work |
Posted: Sun Dec 31, 2006 10:04 pm |
|
|
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: |
|