This is my first post to the group.
I'm designing a heading hold autopilot for a free flight glider. I'm basing it on a PIC16F88, and using an HMC6352 digital compass (http://www.sparkfun.com/datasheets/C...ts/HMC6352.pdf).
I've never played with I2C before, and figured that I would try something simple first, like reading an EEPROM register in the compass module. My problem is that no matter what I do, I seem to always read back a value that is exactly 1/2 of what it should be.
So then I tried writting a value to a RAM address and reading it back. Again, same issue, the value read back is 1/2 the value written.
I'm using PIC BASIC PRO, on a LABX18 development board. Here's the code I'm using for the EEPROM read, which is modified from some of the example programs:
If anyone can point me to the error of my ways, it would be greatly appreciated.Code:Define LCD_DREG PORTA Define LCD_DBIT 0 Define LCD_RSREG PORTB Define LCD_RSBIT 6 Define LCD_EREG PORTB Define LCD_EBIT 3 ' Define I2C Interface SDA Var PORTB.1 ' Data pin SCL Var PORTB.4 ' Clock pin cmd Var Byte addr Var Byte cont Var Byte ANSEL = 0 ' PORTA is digital CMCON = 7 ' PORTA is digital Pause 100 ' Wait for LCD to start up loop1: pauseus 1000 cmd = $72 ' Read from compass EEPROM addr= $00 ' EPROM address $00 I2CWRITE SDA, SCL, $42, [cmd, addr], nowrite pauseus 1000 I2CREAD SDA, SCL, $42, [cont], noread Lcdout $fe, 1, "Data: ", cont goto loop1 End nowrite: Lcdout $fe, 1, "Write Err" goto nowrite noread: Lcdout $fe, 1, "Read Err" goto noread
John Ihlein
Albuqueruqe, NM





Bookmarks