MCP3221 12bit ADC I2C

Hello?

I am trying to rewrite a code, which is written in CCS-C

i2c_start();
i2c_write(0x9B); //MCP3221 address is 0x9B
ad_high = i2c_read(1); //indicate to ack
ad_low = i2c_read(0);
i2c_stop();
ADC_result = (ad_high * 256) + ad_low;

This code works fine with CCS-C, and I modified it as follow, but it does not work
Probably, I need to send ack after reading the first byte, but
do not know how to send ack with Wire.receive

ad_high = Wire.receive(1); // if I put “1”, this makes compile error

Could someone help me?

====================================================
#include <Wire.h>
#define ADDRESS 0x9B //defines address of MCP3221 12bit ADC
void setup(){
Wire.begin(); //conects I2C
Serial.begin(9600);
}

void loop(){
byte ad_high;
byte ad_low;
int Result;

Serial.println(“Let’s begin”);
Wire.beginTransmission(ADDRESS);
ad_high = Wire.receive();
ad_low = Wire.receive();
Wire.endTransmission();

Result = (ad_high * 256) + ad_low;

Serial.println(Result);
delay(100);
}

Thanks
Eaton

I found an answer myself Address of Wire.requestFrom should be 7 bits, not 8 bits

can you post your working version for future reference? Thank you.

This is a working code

#include <Wire.h>

#define ADDRESS 0x4D // 7 bits address is 0x4D, 8 bits is 0x9B

void setup(){
Wire.begin(); //conects I2C
Serial.begin(115200);
}

void loop(){
byte ad_high;
byte ad_low;
int Result;

Wire.requestFrom(ADDRESS, 2); //requests 2 bytes
while(Wire.available() < 2); //while two bytes to receive

ad_high = Wire.receive();
ad_low = Wire.receive();
Result = (ad_high * 256) + ad_low;

Serial.println(Result);

delay(10);
}