Jump to content
Sign in to follow this  
ckd

HMC5883L (GY-80) interfacing with TM4C1294XL

Recommended Posts

I am working on TM4C1294XL board and through Energia platform. I am trying to interface HMC5883L of GY-80 with TM4C1294XL board. I am getting static outputs irrespective of whether I initialize all the essential registers or initialize none, the static outputs do not change in both cases. I am pasting the code below, I suspect that something should be wrong with the code as there nothing much to do in connection (only four wires needed). 

#include "Wire.h"

#define cra 0x00
#define crb 0x01
#define modeReg 0x02
#define data_X_MSB 0x03
#define data_X_LSB 0x04
#define data_Y_MSB 0x07 
#define data_Y_LSB 0x08
#define data_Z_MSB 0x05
#define data_Z_LSB 0x06
#define statusReg 0x09
#define ID_reg_A 0x10 
#define ID_reg_B 0x11
#define ID_reg_C 0x12

int magAddress = 0x1E;
int X0,X1,Y0,Y1,Z0,Z1,X_out,Y_out,Z_out;
float Xm,Ym,Zm;

void setup(){

  Wire.setModule(0);
  Wire.begin();
  Serial.begin(115200);
  delay(100);
  
  Wire.beginTransmission(magAddress);
  Wire.write(modeReg);
  Wire.write(0x00);
  Wire.write(cra);
  Wire.write(0x38);
  Wire.write(crb);
  Wire.write(0xA0);
  Wire.write(data_X_MSB);
  Wire.write(0x00);
  Wire.write(data_X_LSB);
  Wire.write(0x00);
  Wire.write(data_Y_MSB);
  Wire.write(0x00);
  Wire.write(data_Y_LSB);
  Wire.write(0x00);
  Wire.write(data_Z_MSB);
  Wire.write(0x00);
  Wire.write(data_Z_LSB);
  Wire.write(0x00);
  Wire.endTransmission();
  }

void loop(){
  
  Wire.beginTransmission(magAddress);
  Wire.write(data_X_LSB);
  Wire.write(data_X_MSB);
  Wire.endTransmission();
  Wire.requestFrom(magAddress,2);
  if(Wire.available()<=2)
  {
    X0 = Wire.read();
    X1 = Wire.read();

    X1 = X1<<8;
    X_out = X0+X1;
    Xm = (X_out);
  }

  Wire.beginTransmission(magAddress);
  Wire.write(data_Y_LSB);
  Wire.write(data_Y_MSB);
  Wire.endTransmission();
  Wire.requestFrom(magAddress,2);
  if(Wire.available()<=2)
  {
    Y0 = Wire.read();
    Y1 = Wire.read();

    Y1 = Y1<<8;
    Y_out = Y0+Y1;
    Ym = (Y_out);
  }

  Wire.beginTransmission(magAddress);
  Wire.write(data_Z_LSB);
  Wire.write(data_Z_MSB);
  Wire.endTransmission();
  Wire.requestFrom(magAddress,2);
  if(Wire.available()<=2)
  {
    Z0 = Wire.read();
    Z1 = Wire.read();

    Z1 = Z1<<8;
    Z_out = Z0+Z1;
    Zm = (Z_out);
  }

  Serial.print("Xm = ");
  Serial.print(Xm);
  Serial.print("\t");
  Serial.print("Ym = ");
  Serial.print(Ym);
  Serial.print("\t");
  Serial.print("Zm = ");
  Serial.println(Zm);

  delay(200);
  
}

 

Share this post


Link to post
Share on other sites

Hi ! @Rei Vilo

I think something was wrong with the board as when I checked its clock, it didn't look like a clock signal but more as a noise signal. Then I used I2C3 but then I stopped getting outputs. Then I checked the code on the TM4C123GXL, the smaller version, I got the outputs!!! I do not know what was wrong with the board. If someone also experienced similar experience with the board then please tell me how to sort that out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×