MCP3221 12bit ADC I2C
hello?
i trying rewrite code, written in ccs-c
i2c_start();
i2c_write(0x9b); //mcp3221 address 0x9b
ad_high = i2c_read(1); //indicate ack
ad_low = i2c_read(0);
i2c_stop();
adc_result = (ad_high * 256) + ad_low;
this code works fine ccs-c, , modified follow, not work
probably, need send ack after reading first byte, but
do not know how send ack wire.receive
ad_high = wire.receive(1); // if put "1", makes compile error
could 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 trying rewrite code, written in ccs-c
i2c_start();
i2c_write(0x9b); //mcp3221 address 0x9b
ad_high = i2c_read(1); //indicate ack
ad_low = i2c_read(0);
i2c_stop();
adc_result = (ad_high * 256) + ad_low;
this code works fine ccs-c, , modified follow, not work
probably, need send ack after reading first byte, but
do not know how send ack wire.receive
ad_high = wire.receive(1); // if put "1", makes compile error
could 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 answer myself
address of wire.requestfrom should 7 bits, not 8 bits
address of wire.requestfrom should 7 bits, not 8 bits
Arduino Forum > Using Arduino > Programming Questions > MCP3221 12bit ADC I2C
arduino
Comments
Post a Comment