Vsm i2c simulation of mcp23017

Hi, can someone put me out of my misery please
I've been trying to learn how to use the MCP23017 expander via I2c protocol
but no matter what i do I cannot get it to simulate on VSM
My knowledge of I2C protocol is basic so I've been using examples posted on the forum as a learning aid, but without success.
So the question needs to be asked,
does VSM actually simulate I2C with the MP23017 ??

thanks
 

nick12ab

Senior Member
I don't have VSM, but could you post your code so that it can be confirmed that you are using a hi2csetup command and with the correct slave address.
 
I don't have VSM, but could you post your code so that it can be confirmed that you are using a hi2csetup command and with the correct slave address.

Sure happy to,

I am not sure of what am doing, so to learn I have tried many versions including writei2c commands as well, frustratingly without success.
I am using the new version of VSM

I have mainly been using hi2c commands instead of i2c commands as recommended in manual2
Unfortunately the i2c tutorial focuses on these older commands so is not really a help.

;Code for BASIC test of MCP23017, based from code posted by westaust55
;USING 40X2 ON VSM

SYMBOL mcp23017 = %01000000 ; $0100 A2, A1, A0, R/W all connected to 0V
SYMBOL IODIRA = $00 ; Port A IO Direction register DEFAULT = I/P
SYMBOL IODIRB = $01 ; Port B IO Direction register DEFAULT = I/P
SYMBOL IOCON = $0A ; IO Expander config register - address $0B accesses the same register
SYMBOL GPIOA = $12 ; Port A General purpose register
SYMBOL GPIOB = $13 ; Port B General Purpose register

HI2CSETUP i2cmaster, mcp23017, i2cFAST_8, i2cbyte
; I have tried i2cfast, i2cslow_8,
PAUSE 100

HI2COUT IODIRA, ($FF) ;set all port A pins as inputs (1)
HI2COUT IODIRB, ($00) ;set all port B pins as outputs (0)

PAUSE 100

HI2COUT $12, (%11111111) ; all ON
PAUSE 300
HI2COUT $12, (%00000000) ; all OFF
PAUSE 300

HI2COUT $13, (%11111111) ; all ON
PAUSE 300
HI2COUT $13, (%00000000) ; all OFF
PAUSE 300


Main:
DO
b3 = 1
DO ; LED dot pattern to move left
HI2COUT GPIOB, (b3)
b3 = b3 << 1 ; shift left 1 bit
PAUSE 500
LOOP UNTIL b3 = 0

b3 = 64
DO ; LED dot pattern to move right
HI2COUT GPIOB, (b3)
b3 = b3 >> 1 ; shift right 1 bit
PAUSE 500
LOOP UNTIL b3 = 1

LOOP

Thanks for your help
 

hippy

Technical Support
Staff member
So the question needs to be asked,
does VSM actually simulate I2C with the MP23017 ??
Your code seemed to work for me without any changes when I tried it, so it seems -

1) You haven't wired the MCP23017 correctly; ensure /RESET goes to +V, A2/A1/A0 to 0V, SCL/SDA go to the correct 40X2 pins, aren't crossed-over and have pull-ups..

2) My VSM setup is different to your, which is possible as X2's are Beta releases.

Perhaps post your .DSN file so those with PICAXE VSM can check and test that.
 
Your code seemed to work for me without any changes when I tried it, so it seems -
1) You haven't wired the MCP23017 correctly; ensure /RESET goes to +V, A2/A1/A0 to 0V, SCL/SDA go to the correct 40X2 pins, aren't crossed-over and have pull-ups..
THANK YOU VERY VERY MUCH
You were right !!

I hadn't connected the RESET to +ve

Now it works fine.
I really appreciate your help,
if my hair was long i probably would have pulled it out by now.
Cheers
 
Top