memsic i2c accelerometer trouble

profmason

Member
Memsic has a relatively new dual axis accelerometer 6202 with an i2C interface. It is available in single quantities very inexpensively. It is also available on a carrier board from gravitech.us. I have had good luck getting it to work with the BS2p, but have been fighting with making it work with the picaxe 18x.
I attach SDA and SCL to the appropriate pins and pull them up through 4.7k resistors. I power and ground the chip.
The code I am using is:
symbol MXC6202 = %00010000 'checked with part code on chip

i2cslave MXC6202, i2cslow, i2cbyte 'initialize part
pause 100

Main:
readi2c 0, (b0,b1,b2,b3,b4) 'register, MSBx, LSBx, MSBY,LSBY
sertxd (#b0,",",#b1,",",#b2,",",#b3,",",#b4,13,10)
pause 100
goto Main

This doesn't work. (It outputs a series of 255s meaning that the bus is pulled up)
If I try inserting writei2c (0) before each read command, the serial out starts spitting out repetitive noise. (It is not clear if this is necessary from my reading of the data sheet and i2c reference)
Here is a link to the datasheet.
http://gravitech.us/MicroResearch/I2C/I2C-ACC/MXC6202xJ.pdf

Thanks for any help!
 

Technical

Technical Support
Staff member
What a terribly written datsheet!

Our guess at understanding it is

i2cslave MXC6202, i2cslow, i2cbyte 'initialize part
writei2c 0, (0) ' wake up
pause 100

Main:
readi2c 0, (b0,b1,b2,b3,b4) 'register, MSBx, LSBx, MSBY,LSBY
sertxd (#b0,",",#b1,",",#b2,",",#b3,",",#b4,13,10)
pause 100
goto Main

You can also power down the chip via
writei2c 0, (1)
 

Technical

Technical Support
Staff member
symbol MXC6202 = %00010000

Also this can't be right - 10H. If your part is 20H then you need

symbol MXC6202 = %00100000
 

profmason

Member
Ok, I updated the code to:

symbol MXC6202 = $20

i2cslave MXC6202, i2cslow, i2cbyte
writei2c 0,(0)
pause 100

Main:
readi2c 0, (b0,b1,b2,b3,b4) 'register, MSBx, LSBx, MSBY,LSBY
sertxd (#b0,",",#b1,",",#b2,",",#b3,",",#b4,13,10)
pause 100
goto Main

Still getting 255,255,255,255 etc.

I had been using the correct slave ID earlier but I blew it on the version I posted!

Still stumped. If anyone else has any ideas let me know! I will chat with the folks who made the dev board and see if they have any ideas.

Thanks!

 

Technical

Technical Support
Staff member
It's always worth a triple check that SDA and SCL are connected the correct way around.
 

hippy

Senior Member
It's probably also worthwhile going back to BS2 testing just to check the device is still working as expected and hasn't suffered any damage.
 

atharvai

Senior Member
i noticed ur command "i2cslave MXC6202, i2cslow, i2cbyte" in the data sheet says it operates in FAST mode so surely it should be "i2cslave MXC6202, i2cfast, i2cbyte"

change the i2cslow to i2c fast and see if it works
pg7 under SDA and SCL



Edited by - atharvai on 15/05/2007 22:05:28
 

profmason

Member
Thanks for all the suggestions! I tried using i2cfast just to be sure and it still didn't work. I will have to get the basic stamp back out and see if the board is still working.
 
Top