Which do you have?For the VSSOP version of the ADC121C021, this address is configured by the ADR0 and ADR1 addres selection inputs. For the ADC121C027, the address is configured by the ADR0 address selection input. ADR0 and ADR1 can be grounded, left floating, or tied to VA. If desired, ADR0 and ADR1 can be set to VA/2 rather than left floating. The state of these inputs sets the hardware address that the ADC responds to on the I2C bus (see Table 1). For the ADC121C021, the hardware address is not pin-configurable and is set to 1010100.
I am just trying to understand datasheet I don't have any hardware in hand I am looking for version given in the source code. Why 0x50(80) is the address of Slave?Depending on the package, ADC121C021 has selectable address or not:
Which do you have?
As you see in the datasheet, address 0x50 is achieved with VSSOP version of ADC121C021 by leaving both ADR pins open (floating).
Correct.what would be sequence to Writing data to an ADC Register?
Send Frame 1 that is slave address = 0x50
send frame 2 that is configuration register = 0x02
next is Frame 3
The new value of the configuration register.What would be the value of frame 3 in figure 33 (a)?
Correct.
The new value of the configuration register.
alright I want to write 0x20Depends on which value you want to write to the configuration register. You didn't yet tell.
Right. 16-bit registers are written with two data bytes, configuration register with one.
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// ADC121C021
// This code is designed to work with the ADC121C021_I2CADC I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Analog-Digital-Converters?sku=ADC121C021_I2CADC#tabs-0-product_tabset-2
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
void main()
{
// Create I2C bus
int file;
char *bus = "/dev/i2c-1";
if((file = open(bus, O_RDWR)) < 0)
{
printf("Failed to open the bus. \n");
exit(1);
}
// Get I2C device, ADC121C021 I2C address is 0x50(80)
ioctl(file, I2C_SLAVE, 0x50);
// Select configuration register(0x02)
// Automatic conversion mode enabled(0x20)
char config[2] = {0};
config[0] = 0x02;
config[1] = 0x20;
write(file, config, 2);
sleep(1);
// Read 2 bytes of data from register(0x00)
// raw_adc msb, raw_adc lsb
char reg[1] = {0x00};
write(file, reg, 1);
char data[2] = {0};
if(read(file, data, 2) != 2)
{
printf("Error : Input/Output Error \n");
}
else
{
// Convert the data to 12-bits
int raw_adc = ((data[0] & 0x0F) * 256) + data[1];
// Output data to screen
printf("Digital Value of Analog Input : %d \n", raw_adc);
}
}
Right. 16-bit registers are written with two data bytes, configuration register with one.
If the datasheet does not clearly describe a function, then better not use it.Can I store data at any register or do I have to store data in a sequence like First have to write the data at the configuration register. And then store in other register
The datasheet nowhere mentiones automatic address increment ... thus - maybe you re-write the current register instead of the next register...For a single byte transfer, the master should generate a stop condition at this point. For a 2-byte write operation, the lower 8-bits are sent by the master. The ADC121C021 then ACKs the transfer, and the master either sends another pair of data bytes, generates a Repeated Start condition to read or write another register, or generates a Stop condition to end communication.
Hi,
If the datasheet does not clearly describe a function, then better not use it.
Indeed the datasheet is not clear with this.
It mentiones
The datasheet nowhere mentiones automatic address increment ... thus - maybe you re-write the current register instead of the next register...
--> Start independent write operations.
Klaus
Yes. But what is your question?There are two parts in I2C communication, I2C Read and I2C Write
I'm not sure I understand your question.The ADC121C021 has 8 internal data registers and one address pointer. Figure 24. Register Structure, Which register of ADC I have to write the data to read the analog input and Which address of register I have to read the analog input
Hi,
Yes. But what is your question? I'm not sure I understand your question.
Klaus
I think, the purpose of all registers is well explained in datasheet. The ADC can be however operated without writing to any register, just using the default pointer value of 0 and conversion on demand by repeatedly reading the result register.
There are ALL details given in the datasheet.There are not more details about the configuration register in the datasheet. Can you tell me how to configure configuration register to read the analog data?
All the configuration register bit definitions for the device are described in the datasheet that you posted in #1There are ALL details given in the datasheet.
And this is where we have our knowledge from. .. Just from reading the datasheet. ( I´ve never heared of this IC before this thread. )
My question: Did you even try to read the conversion result?
* yes: What results did you get? What results did you expect?
* no: then read the conversion result...
I am just trying to understand datasheet I don't have any hardware in hand I am looking for version given in the source code. Why 0x50(80) is the address of Slave?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?