Changing the address of I2C in compass?

Thread Starter

SaraSa

Joined Feb 11, 2009
25
Dear friends,
I have a CMPS03 and I want to change the address.
I have read the related link, but whatever I wrie the program, I could not get any reply!
the link is below:
http://www.robot-electronics.co.uk/htm/cmps3tech.htm

the last idea was below, but it was not effective:
%%%%%%

I2caddr = &HC0
I2cstart
I2creg = 12
I2csend I2caddr , I2creg
I2creceive I2caddr , I2cdata
'I2cstop

I2cstart
I2creg = 13
I2csend I2caddr , I2creg
I2creceive I2caddr , I2cdata
' I2cstop


I2creg = 14
I2csend I2caddr , I2creg
I2creceive I2caddr , I2cdata
' I2cstop

I2creg = 15
I2csend I2caddr , I2creg
I2creceive I2caddr , I2cdata
' I2cstop



I2caddr = &HC2
I2cstart
I2creg = 2
I2csend I2caddr , I2creg
I2creceive I2caddr , I2cdata
I2cstop


%%%%%%
Any help will be appreciated.
Best Regards,
Sara
 

ErnieM

Joined Apr 24, 2011
8,377
I don't recognise what compiler this may be so I have to guess how these library calls work. So I'll give it in psudo calls and you'll have to stuff back into your library code.

First, we need to address this thing at the address it is at, and that may have changed... but assume it is at the initial 0xC0 and not 0xC2, or 0xC4, or 0xC6, or 0xC8, or 0xCA, or 0xCC or even 0xCE.

You first send the address, the register, then the data. Registers auto increment from the first setting. After each data word you send the ACK bit needs to be checked (low for true)... I have no idea if your lib calls do this.

SendSTART;
SendData 0xC0; // slave address
CheckAck;
SendData 0xc0; // register 12(=C)
CheckAck;
SendData 0xA0; // unlock code one
CheckAck;
SendData 0xAA; // unlock code two
CheckAck;
SendData 0xA5; // unlock code three
Check Ack;
SendData 0xC8; // New I2C Address... using C8 here
SendSTOP;


(I agree, putting a link there is most kind of you.)
 

Thread Starter

SaraSa

Joined Feb 11, 2009
25
I don't recognise what compiler this may be so I have to guess how these library calls work. So I'll give it in psudo calls and you'll have to stuff back into your library code.

First, we need to address this thing at the address it is at, and that may have changed... but assume it is at the initial 0xC0 and not 0xC2, or 0xC4, or 0xC6, or 0xC8, or 0xCA, or 0xCC or even 0xCE.

You first send the address, the register, then the data. Registers auto increment from the first setting. After each data word you send the ACK bit needs to be checked (low for true)... I have no idea if your lib calls do this.

SendSTART;
SendData 0xC0; // slave address
CheckAck;
SendData 0xc0; // register 12(=C)
CheckAck;
SendData 0xA0; // unlock code one
CheckAck;
SendData 0xAA; // unlock code two
CheckAck;
SendData 0xA5; // unlock code three
Check Ack;
SendData 0xC8; // New I2C Address... using C8 here
SendSTOP;


(I agree, putting a link there is most kind of you.)
Please tell me, Is the below lines are effective or not?
I work with BASCOM (in Basic Language)
Did you mean these programs?

%%%%%

I2cstart
I2caddr = &HC0
Ack
I2creg = 12
I2csend I2caddr , I2creg , Ack

I2caddr = &HA0
I2creg = 13
I2csend I2caddr , I2creg , Ack

I2caddr = &HAA
I2creg = 14
I2csend I2caddr , I2creg , Ack

I2caddr = &HA5
I2creg = 15
I2csend I2caddr , I2creg , Ack

I2caddr = &HC8
I2creceive I2caddr , I2cdata
I2cstop

%%%%%%%%%


Another question is that:
IS not necessary to use Ack and Nack together??

Any help will be appreciated.
Best Regards,
Sara
 

ErnieM

Joined Apr 24, 2011
8,377
As it says in the data sheet "You can do this in one transaction, setting the register address to 12 and writing the four bytes. The internal register pointer is incremented automatically." So my code is attempting to do just that (meaning I've worked plenty with I2C but never with this particular compiler). One transaction means we send everything between one start and one stop signals:

Rich (BB code):
I2CSTART
I2CWBYTE 0xC0 ' slave address
I2CWBYTE 0xC0 ' register 12(=C)
I2CWBYTE 0xA0 ' unlock code one
I2CWBYTE 0xAA ' unlock code two
I2CWBYTE 0xA5 ' unlock code three
I2CWBYTE 0xC8 ' New I2C Address... using C8 here
I2CSTOP
That's it, if I understood your compiler's help file that should be all the code to set the address from C0 to C8.
 

ErnieM

Joined Apr 24, 2011
8,377
My previous post has a HUGE error: I set the register address incorrectly, so the unlock code and new address will not work.

Rich (BB code):
I2CSTART
I2CWBYTE 0xC0 ' slave address       <---(see note below)
I2CWBYTE 0x0C ' register 12(=0x0C)  <--- line was in error!!!
I2CWBYTE 0xA0 ' unlock code one
I2CWBYTE 0xAA ' unlock code two
I2CWBYTE 0xA5 ' unlock code three
I2CWBYTE 0xC8 ' New I2C Address... using C8 here
I2CSTOP
Note: if the address was ever successfully changed then the new address must be used here and for all other transactions.

Also note that an I2C device will ACK each byte of data when it is properly addresses. An oscilloscope can easily see this. If you don't have a scope you can take advantage of I2C working at any frequency, so you can slow it down and even pause the lines until you could even use a pair of LEDs to watch the bytes go by.
 
Top