Shop OBEX P1 Docs P2 Docs Learn Events
Problems with Compass Parallax #29323 (HMC6352) — Parallax Forums

Problems with Compass Parallax #29323 (HMC6352)

mohamedelnonomohamedelnono Posts: 6
edited 2011-01-23 12:40 in Accessories
i have a problem in programming the compass any one help me please
i used pic micro
i use proton basic for programming

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-22 20:11
    I'm sorry, we can't help you with PIC programming or with Proton Basic programming. If you have questions about the compass itself and how it works, we can help with that and there are sample programs for using the compass with both the Stamps and the Propeller on the product webpage for the compass (here).
  • mohamedelnonomohamedelnono Posts: 6
    edited 2011-01-23 10:44
    I2C_Write:
    I2C_LSB = I2C_DATA.BIT0 ' Store the status of the LSB
    I2C_DATA = I2C_DATA / 2
    SHIFTOUT SDA, SCL, MSBFIRST, [I2C_DATA\7] ' Write out the first 7 bits, MSB first
    IF I2C_LSB THEN INPUT SDA ELSE LOW SDA ' Write the 8th bit
    i have question in the if condition
    what does it mean in this case if IF I2C_LSB Then if what ?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-23 12:40
    Look 3 lines up in the program, you have "I2C_LSB = I2C_DATA.BIT0". I assume that I2C_DATA is a variable with an 8 bit value in it. This statement extracts bit # 0 (the least significant bit) and stores it in another variable (I2C_LSB). The divide by 2 is the same as a right shift by one bit. The SHIFTOUT sends the remaining 7 bits and produces a clock for each bit. The last IF checks I2C_LSB which is holding the original least significant bit of the data, then either sets the data pin to input mode (high impedance) or to a low output.

    This group of statements sends an 8-bit value and leaves the SDA line in an appropriate state for the I2C bus, namely either high impedance or logic low.

    There are descriptions of how the I2C bus works in the Wikipedia and in pretty much any datasheet for an I2C device like the compass.
Sign In or Register to comment.