Shop OBEX P1 Docs P2 Docs Learn Events
HMC 6352 Default Address — Parallax Forums

HMC 6352 Default Address

russnagel1russnagel1 Posts: 1
edited 2011-06-15 05:50 in Accessories
My compass is NACK ing when I hit it with the default address 0x42. I have checked this out with a scope and the SCL line has a freq of 100kHz and the data line is showing 0x42 with the last bit (NACK) being high. The debugger does show the start condition was transmitted properly.

Can I reprogram the address if I don't have it's address?

Here is my code. I am using WINAVR 4.18 with SP 3. I have a JTAGICE MKII for the programmer debugger.

#include <util/delay.h>
#include "lcd.h"
#include <stdlib.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
//#include "TWI_Master.h"
char buffer[5]; //create array for compass value
int headingHighByte;
int headingLowByte;
int heading;
#define Start() TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN) //Send START signal
#define Action_Clear() TWCR = (1<<TWINT)|(1<<TWEN) //Perform Action and clear TWINT flag
#define Wait() while (!(TWCR & (1<<TWINT))) //Wait for TW hardware to send data
#define Stop() TWCR=(1<<TWINT)|(1<<TWSTO)|(1<<TWEN) //Send STOP Signal

int main(){
while(1){
TWBR = 2; //Set bit rate to 100Khz with 2 Mhz clock prescalar = 0
Start(); //Initialize communication with compass
Wait();
TWDR = 0x42; //Compass Write Address
Action_Clear();
Wait();
TWDR = 0x41; //Command A to get compass heading
//_delay_ms(6); //give compass extra time to get heading
Action_Clear();
Wait();
Stop(); //Send stop condition
Start(); //Send restart with read address
TWDR = 0x43; //Read Address
Action_Clear();
Wait();
headingHighByte = TWDR;
Action_Clear();
headingLowByte = TWDR;
Action_Clear();
Stop();
heading = (headingHighByte<<8)|(headingLowByte<<0); //Build heading data //heading = 1111;
lcd_init(LCD_DISP_ON); //Send to LCD
lcd_clrscr();
itoa(heading,buffer,10);
lcd_puts(buffer);
//_delay_ms(500);
}//end of while
}// end of main
Sign In or Register to comment.