I2c problem

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Mast
Posts: 65
Joined: Wed Aug 29, 2007 6:24 am
Location: France

I2c problem

Post by Mast » Mon Sep 24, 2007 6:27 am

This is my code, work fine with 18F452 but nothing with 18F4682 or 4685. Can you help me to andestand why. this is a cmps03 compass. thanks

Code: Select all

I2C.Initialize
I2C.Start                          
I2C.WriteByte($C0)              
I2C.WriteByte(0)
I2C.Restart     
I2C.WriteByte($C1)   
 
sw_revision = I2C.ReadByte
I2C.Acknowledge

ee_byte = I2C.ReadByte
I2C.Acknowledge

ee_high = I2C.ReadByte
I2C.Acknowledge

ee_low = I2C.ReadByte
I2C.WriteByte($C1)

Mast
Posts: 65
Joined: Wed Aug 29, 2007 6:24 am
Location: France

Post by Mast » Mon Sep 24, 2007 8:05 am

i find the problem : i need to put register a the end off readbyte


Register Function
0 Software Revision Number
1 Compass Bearing as a byte, i.e. 0-255 for a full circle
2,3 Compass Bearing as a word, i.e. 0-3599 for a full circle, representing 0-359.9 degrees.
4,5 Internal Test - Sensor1 difference signal - 16 bit signed word
6,7 Internal Test - Sensor2 difference signal - 16 bit signed word
8,9 Internal Test - Calibration value 1 - 16 bit signed word
10,11 Internal Test - Calibration value 2 - 16 bit signed word
12 Unused - Read as Zero
13 Unused - Read as Zero
14 Calibration Done Flag - Zero in calibrate mode when un-calibrated, 255 otherwise - unused in Rev 7 software & CMPS03
15 Calibrate Command - Write 255 to enter calibrate mode, write zero to exit. See text.

Code: Select all

sw_revision = 0 
sw_revision = I2C.ReadByte(0)
I2C.Acknowledge

ee_byte = 0
ee_byte = I2C.ReadByte(1)
I2C.Acknowledge

ee_high = 0
ee_high = I2C.ReadByte(???????????)
I2C.Acknowledge

How can i put register 2 at the end off ee_high = I2C.ReadByte(?????)

Mast
Posts: 65
Joined: Wed Aug 29, 2007 6:24 am
Location: France

Post by Mast » Mon Sep 24, 2007 9:40 am

i find the problem

Post Reply