PDA

View Full Version : I2C with MCP23016



sebastien
- 19th April 2010, 19:15
Hi, i'm trying to get this IO expander chip to work with a 18F8720(have others in stock and same results), I wired the clock and i'm able to measure it at the TestPin of the MCP and i get a 1Mhz clock there, on the SDL, SCL lines(pulled up by 2 (4.7K resistors), i can see, something passing on my scope, but when the device does not put its port 0 to outputs and do not drive them, i think they are floating, in order of 2mV so nothing meanfull, tried to pull them up and down. But no luck.

Here is the code i use

ADCON0 = 0;
ADCON1 = %00001111;
DEFINE OSC 24
DEFINE I2C_SLOW
PAUSE 200
ct var byte
reg var byte
val VAR BYTE
ct = %01000000
reg = $6
val = 0
' Set direction for PORT0 to all outs
I2CWrite PORTC.4,PORTC.3, ct,reg,[val]
main:
LOW PORTH.0
reg = $0 'MCP23... IO LATCH
val = 255
I2CWrite PORTC.4,PORTC.3,ct,reg,[val]
PAUSE 500
HIGH PORTH.0
reg = $0 'MCP IO LATCH
val = 0
I2CWrite PORTC.4,PORTC.3, ct,reg,[val]
PAUSE 500
goto main

sebastien
- 19th April 2010, 21:10
i got the code working by stripping the reg value and using a PCF8574 which has no clock circuit, and it worked directly, this lead me to re-analize the clock on the test pin of the MCP and i got a quite noisy signal, how can i get this more stable, i tried adding condos at the powersupply but still got noise on it. i assume that due to an unstable clock, the data is not handled right by the device.

Melanie
- 20th April 2010, 00:56
You've not told us how your MCP23016 is connected.

Do a SEARCH on MCP23016 on this forum - there are code examples.

sebastien
- 20th April 2010, 08:43
Hi melanie,
the mcp is on portc.3 and 4 for SDA SCL, and thats it. All vss & vdd's are connected and address pins are all grounded.
I've seen those code samples and I inpired my code from them, but it doesn't want to work...grrrr. I don't get anything on the outputs of the MCP.
I really think it is more a clock issue, on the MCP, than an I2C problem. I've tested other I2C devices and they work, they do not need an external RC.

The datasheet says 33Pf and 3.9KOhms for a res and condo between clk pin of the mcp and VSS,VDD.
That should give a 1Mhz clock on test pin, but that clock is very unstable here, and i can't clean it out.

Regards

eggman
- 20th April 2010, 08:49
I ones worked with those chips, I only had it working without the 33 pF capacitor. The MCP23017 seems a better choice, it does not need an external capacitor.

Acetronics2
- 20th April 2010, 09:08
Hi, Sebastien

an interesting reading: Microchip AN 245 ...

Alain

sebastien
- 20th April 2010, 11:03
I ones worked with those chips, I only had it working without the 33 pF capacitor. The MCP23017 seems a better choice, it does not need an external capacitor.

Yeah I prefered the 17's but i could not grab that chip at my local store so gone for the 16. I will try without the cap. Thanks for that tip

I'm now managing to do it with the philips component, but it has only 8, so i will have to make 2 other SDA, SCL lines.

sebastien
- 20th April 2010, 11:04
Hi, Sebastien

an interesting reading: Microchip AN 245 ...

Alain

Seen that appnote and did not find new info compared to the datasheet.
But thanks anyway