PDA

View Full Version : MCP23016 I/O expander with PBP?



Jon Chandler
- 25th September 2004, 09:33
I'm trying to use a MCP23016 I/O expander with a 16F628 running at 20 MHz using I2C. No luck making it work but a Maxim LED driver sharing the I2C lines works great.

I'm using Porta.0 and Porta.1 for the I2C interface. Each line has a 4.7k pullup resistor. All three address lines on the MCP23016 are tied low.

I've got a DEFINE OSC 20 at the start of the program.

My commands are as follow:

First, I initialize the MCP23016 to make all pins outs:

I2CWRITE porta.0,porta.1,%01000000,$06,[%00000000, %00000000] 'all outputs

Then I try to cycle the outputs high and low:

I2CWRITE porta.0,porta.1,%01000000,$00,[%11111111, %11111111] 'RELAYS ON

PAUSE 5000

I2CWRITE porta.0,porta.1,%01000000,$00,[%00000000, %00000000] 'RELAYS off

pause 5000


Looping through the on/off commands causes no changes on any of the outputs.

The MCP23016 data sheet isn't entirely clear to me but I believe I just need to write data to the GP0 and GP1 registers without needing to do anything with the latch registers.

Any ideas? Thanks!

Jon

mister_e
- 25th September 2004, 11:02
hi Jon,
did you

1. add COMCON1=0 at the begining of your program
2. add PAUSE 100 at the begining (PWRT of MCP23016 need 72ms
3. test CLK (pin 9) to see if oscillator work at about 1 MHZ
4. use %0100000 instead of %01000000 (one zero less) for
your address (that's what the datasheet says)
5. add PAUSE 10 after each I2CWRITE
6. write same to IODIR0 and IODIR1 registers
7. Use DEFINE I2C_SLOW 1 (but your device is suppose to
support fast I2C)


the datasheet is indeed not to clear (like every microchip datasheet) but as i think you may need to latch your outputs. Try to do it at the begining

I2CWRITE %0100000,$02,[$FF,$FF] ; LATCH OLAT0
I2CWRITE %0100000,$03,[$FF,$FF] ; LATCH OLAT1

i hope this will help.

let me know

Mister_e

scholar
- 22nd August 2005, 09:32
Hello, I am also developing the I/O expansion using MCP23016, and i use PIC16F77 as microcontroller. I am having problem to make it works also. Even with the code added as mentioned by you. Can anyone expalin briefly to me the steps required to make the MCP23016 work?

A thousands thank you......