src/AS5600.cpp
word AMS_5600::readTwoBytesTogether(int addr_in)
{

  // use only for Angle, Raw Angle and Magnitude

  // read 2 bytes together to prevent getting inconsistent
  //    data while the encoder is moving
  // according to the datasheet the address is automatically incremented
  //    but only for Angle, Raw Angle and Magnitude
  // the title says it's auto, but the paragraph after it
  //    says it does NOT
  // tested and it does auto increment
  
  // PAGE 13: https://ams.com/documents/20143/36005/AS5600_DS000365_5-00.pdf
  // Automatic Increment of the Address Pointer for ANGLE, RAW ANGLE and MAGNITUDE Registers
  // These are special registers which suppress the automatic
  // increment of the address pointer on reads, so a re-read of these
  // registers requires no I²C write command to reload the address
  // pointer. This special treatment of the pointer is effective only if
  // the address pointer is set to the high byte of the register.

  /* Read 2 Bytes */
  Wire.beginTransmission(_ams5600_Address);
  Wire.write(addr_in);
  Wire.endTransmission();
  Wire.requestFrom(_ams5600_Address, (uint8_t) 2);
  while (Wire.available() < 2)
    ;
  
  int highByte = Wire.read();
  int lowByte  = Wire.read();

  // in case newer version of IC used the same address to
  //    store something else, get only the 3 bits
  //return ( ( highByte & 0b111 ) << 8 ) | lowByte;

  // but in case newer version has higher resolution
  //    we're good to go
  return ( highByte << 8 ) | lowByte;
}
/*******************************************************
  Method: readTwoBytes
  In: two registers to read
  Out: data read from i2c as a word
  Description: reads two bytes register from i2c
*******************************************************/
readTwoBytes
In: two registers to read
Out: data read from i2c as a word
Description: reads two bytes register from i2c
readTwoBytes In : two registers to read Out : data read from i2c as a word Description : reads two bytes register from i2c
word AMS_5600::readTwoBytesTogether(int addr_in)
{
  Wire.beginTransmission(_ams5600_Address);
  Wire.write(addr_in);
  Wire.endTransmission();
  Wire.requestFrom(_ams5600_Address, (uint8_t) 2);
  while (Wire.available() < 2)
    ;
  int highByte = Wire.read();
  int lowByte  = Wire.read();
  return ( highByte << 8 ) | lowByte;
}
word AMS_5600 :: readTwoBytesTogether ( int addr_in ) { Wire . beginTransmission ( _ams5600_Address ) ; Wire . write ( addr_in ) ; Wire . endTransmission ( ) ; Wire . requestFrom ( _ams5600_Address , ( uint8_t ) 2 ) ; while ( Wire . available ( ) < 2 ) ; int highByte = Wire . read ( ) ; int lowByte = Wire . read ( ) ; return ( highByte << 8 ) | lowByte ; }
Method: readTwoBytes
In: two registers to read
Out: data read from i2c as a word
Description: reads two bytes register from i2c
Method : readTwoBytes In : two registers to read Out : data read from i2c as a word Description : reads two bytes register from i2c
// use only for Angle, Raw Angle and Magnitude // read 2 bytes together to prevent getting inconsistent //    data while the encoder is moving // according to the datasheet the address is automatically incremented //    but only for Angle, Raw Angle and Magnitude // the title says it's auto, but the paragraph after it //    says it does NOT // tested and it does auto increment // PAGE 13: https://ams.com/documents/20143/36005/AS5600_DS000365_5-00.pdf // Automatic Increment of the Address Pointer for ANGLE, RAW ANGLE and MAGNITUDE Registers // These are special registers which suppress the automatic // increment of the address pointer on reads, so a re-read of these // registers requires no I²C write command to reload the address // pointer. This special treatment of the pointer is effective only if // the address pointer is set to the high byte of the register. /* Read 2 Bytes */ // in case newer version of IC used the same address to //    store something else, get only the 3 bits //return ( ( highByte & 0b111 ) << 8 ) | lowByte; // but in case newer version has higher resolution //    we're good to go