here is some more detaield explanation.
I will stick with older i2c commands for now as none of the enquirers has indicate exactly which PICAXE they have.
From the datasheet I see:
Pull-up resistance values of about 10k ohms are recommended with a nominal 3.0-volt supply voltage.”
A lower value is typically better for higher speeds so although the speed is slow, suggest 4.7KOhm in lieu opf 10kOhm.
From the datasheet I see:
“HMC6352 7-bit slave address is 42(hex) for write operations”
And
“The data rate is the standard-mode 100kbps rate as defined in the I2C Bus Specification 2.1.”
Note that the PICAXE will look after the 8th bit for write and read control so always just leave that as “0” so the slave address is always $42.
So the setup line is:
i2cslave $42, i2cslow, i2cbyte
from the manual:
“After the master device sends the 7-bit slave address with the 1-bit Read/Write,
and gets the 1-bit slave device acknowledge bit returned;
the next one to three sent data bytes are defined as the input command and argument bytes.”
So a command to the compass module is in the format:
I2cwrite (command, [extra1], [extra2])
where [extra1[ and [extra2[ are optional and inserted as required without the square brackets.
In query mode, the command byte to read the data is the letter “A” which equates to hex value $41.
So to have the compass module perform a heading detection and provide the heading data we need:
i2cwrite ($41)
Note that after the first “A” command the compass will keep performing heading detections and making the data available at the next read so repeated “A” commands are not required.
The compass will then send two bytes of date for the heading value with the MSB first and the LSB second. Datasheet table 3 indicates a 6000usec delay = 3 milliseconds so first we can add:
Pause 3 ; may later find there is enough system delays to reduce or remove this but use it to start with.
To read this heading data into two byte variables we must use:
I2cread (b1,b0)
Byte variables b1 and b0 equate to the MSB and LSB respectively for word variable w0 so we can see the data in w0.
To see the value in w0 on the PC screen under the programming editor we add the command
Debug
We can then add another pause for a short delay
Pause 10
Then go back and read the compass module again as above.
So in summary:
Code:
i2cslave $42, i2cslow, i2cbyte
i2cwrite ($41)
PAUSE 3
FOR b3 = 0 to 100
I2cread (b1,b0)
DEBUG
PAUSE 10
NEXT b3
I have not delved into all the other modes, registers, etc her but as I read it, the compass should start in a default mode that the above will work.
If you are looking for more help please:
1. indicate what you project is for (assignment, hobby, etc)
2. which PICAXE chip you are using - affects which comamnds we use
3. advise which PICAXE starter/protoboard you are using - then we know if youa re connecting correctly
4. post your code written so far
5. upload your circuit diagram so we can see if that is correct then we know if you are connecting correctly
5 try to get a clear photo of the entire circuit showing all components and clearly showing where each wire is going