AM4096 I2C Read

Hello All,

I am trying to get the Sensor Data as i want to use sinusoidal differential analog outputs.I am new to the Arduino I2c programming but i have tried one program but not getting output.Any help would be appericiated.Datasheet Available Here..http://resources.renishaw.com/en/details/data-sheet-am4096-rotary-magnetic-encoder-ic--79188

Thank You.

//i2c_Am4096
#include <Wire.h>
 const int SLAVE_ADDRESS=0x0000;
 int encodercount=0;



void writeRegister1(long thisRegister, long thisValue) {
  long result = 0;   
Wire.beginTransmission (SLAVE_ADDRESS);
  result = Wire.write(thisRegister);
  result = Wire.write(thisValue);
Wire.endTransmission ();
}


void Initencoder()
{

   writeRegister1(0x0001, 0x4000); 
   writeRegister1(0x0000, 0x8000); 
   writeRegister1(0x0003, 0x0038); 
}
void setup() {
 Serial.begin(115200);
Initencoder(); 

}

void loop() {
 Wire.beginTransmission (SLAVE_ADDRESS);
 Wire.write(0x32);
encodercount = Wire.read ();
encodercount <<= 8;
encodercount|= Wire.read ();
Wire.endTransmission ();
Serial.println(encodercount);
}

Data_sheet_RMK4_evaluation_board.pdf (355 KB)

The first thing that I always do with a new I2C part is connect it up and run the I2C scanner to confirm the device is on the bus and the I2C address is correct.

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200);   //***********  make sure serial monitor baud matches **********

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Hi!
I'm using too this RMK4 kit magnetic encoder with Arduino.
First, you must initialize the i2c with Wire.begin() in setup().

But I can not even show a value, only shows -1:

#include <Wire.h>

const int SLAVE_ADDRESS=0x0000;
int encodercount=0;

void setup()
{  
 Wire.begin();
 Serial.begin(9600);
 Serial.println("Start");

 Serial.print("Encoder Init:");
 initEncoder();
 Serial.println(" ok");
}

void loop()
{
 Wire.beginTransmission (SLAVE_ADDRESS);
 Wire.write(0x32);
 encodercount = Wire.read ();//Read MSB Data
 encodercount <<= 8;
 encodercount = Wire.read (); //Read LSB Data

 Serial.print("Encoder value:   ");
 Serial.println(encodercount);
 Wire.endTransmission(); 
 
 delay(500);
}




void writeRegister1(long thisRegister, long thisValue)
{
 long result = 0;   
 Wire.beginTransmission (SLAVE_ADDRESS);
 result = Wire.write(thisRegister);
 result = Wire.write(thisValue);
 Wire.endTransmission ();
}

void initEncoder()
{
 writeRegister1(0x0001, 0x4000); 
 writeRegister1(0x0000, 0x8000); 
 writeRegister1(0x0003, 0x0038); 
}

Please provide a data sheet for the encoder. You have the address of 0x0000 which is the I2C broadcast address (likely not the encoder's address).

Hi!

Magnetic Encoder AM4096 Datasheet

I run your "I2c scanner", and address is 0x00

Thanks

Indeed, the datasheet specifies 0x00 as the default address. Are there pullup resistors on SDA and SCL?

This entire thread seems a bit strange since the original question was about setting up differential analog output and then goes on to deal with pulling digital data out of the registers. Based on a quick look at the data sheet, I think the analog output is available on pins and not thru i2c. I think there is also a note that the analog output may make the digital values incorrect?

@ Razofra what are you actually trying to do?

@groundfungus Yes, the kit has pull-up resistors

@cattledog For the moment, I only need to read the Rpos register to obtain the position of the magnet

I only need to read the Rpos register to obtain the position of the magnet

You need to spend some time studying the data sheet. This is not a simple device, and I have no direct experience with it. However, from my reading of the data sheet, I think that your initialization of the encoder is wrong for what you are trying to do.

Also, the wire library commands used to read the register are not correct in your code.

Try

#include <Wire.h>

const int SLAVE_ADDRESS=0x00;
int encodercount=0;

void setup()
{  
 Wire.begin();
 Serial.begin(9600);
 Serial.println("Start");

 Serial.print("Encoder Init:");
 initEncoder();
 Serial.println(" ok");
}

void loop()
{
 Wire.beginTransmission(SLAVE_ADDRESS);
 Wire.write(0x32);//register to read from
 Wire.endTransmission();
 Wire.requestFrom(SLAVEADDRESS,2);
 encodercount = Wire.read ();//Read MSB Data
 encodercount <<= 8;
 encodercount |= Wire.read (); //Read LSB Data and combine with MSB

 Serial.print("Encoder value:   ");
 Serial.println(encodercount);
 
 delay(500);
}




void writeRegister1(byte thisRegister, int thisValue)
{
 long result = 0;   
 Wire.beginTransmission (SLAVE_ADDRESS);
 result = Wire.write(thisRegister);
 result = Wire.write(thisValue);
 Wire.endTransmission ();
}

void initEncoder()
{
 writeRegister1(0x01, 0x0000); 
 writeRegister1(0x00, 0x0000); 
 writeRegister1(0x03, 0x0000); 
}

Does anyone know how to enable UVW output on this sensor board? I know that i have to set “BufSel” to 0 and "UVW" to 110 but i have no idea how to do that.

Thanks for the help.

Does anyone know how to enable UVW output on this sensor board? I know that i have to set "BufSel" to 0 and "UVW" to 110 but i have no idea how to do that.

Do you have the data sheet? See the information on page 13. The setting you are asking for on UVW is for 7 pole pairs and a signal period length of 51.4 degrees. Is that what you want?

In the code posted above in reply #8

writeRegister1(0x01, 0x0000); //will set bufsel to 0

To set UVW to 110

writeRegister1(0x03, 0x0030); //will set UVW to 110