PDA

View Full Version : ADC121C021 I2C problems



Electrosolve
- 7th August 2009, 22:17
I am having problems reading a ADC121C021 12 bit ADC with PBP.

From the data sheet it appears that the slave address is 54h and the conversion result register is 0h.

However, when I use the code below I get a read error.

I have written a routine to cycle addresses from 0 to 255 to see if I could find a slave address that does work.

I have found that a slave address of $A8 does return a result but whilst the result for an input of 0 to 5 volts produces an output of 0 to 4096, there seems to be gaps of 8 in the result i.e. 356,364,380 etc.

I'm not sure what is going on.

Any thoughts?

i2cclock var portb.2
i2cdata var portb.1
slave_address var byte
data_read var word
adc_register var byte
slave_address=$54
adc_register=0
I2Cread i2cdata,i2cclock,slave_address,adc_register,[data_read],error
hserout [#data_read,13,10]
program continues --

error:
hserout ["Read error",13,10]

Darrel Taylor
- 8th August 2009, 00:41
I didn't notice the attachment at first, and searched online for the datasheet.

Your's was from 2008, and I found this one at National from April, 2009.
There are considerable differences in the addressing scheme between the two.

And the big question is ... are you using the MSOP-8 package?

See section 1.7.4 I2C Slave (Hardware) Address
http://www.national.com/ds/DC/ADC121C021.pdf

It shows that the addresses should be between A0 and A6, depending on PIN configurations.
<br>

Electrosolve
- 8th August 2009, 08:00
I'm using the TSOT package which has a fixed slave address. The ADDR pin is used as an alert on this one.

I think using an address of A3 should work on my device but it doesn't. I get a response from the device with addresses of A8 and A9. These appear to return the lowest and highest conversion values.

I haven't messed around with the result register pointer as I think it should be at 0h.

Darrel Taylor
- 8th August 2009, 08:49
Ok, I see what happened ...

The address listed in the datasheet is only 7-bits 1010100.
When you add the read/write bit it becomes $A8, 1010:1000

And I think the pointer address should be sent with I2CWRITE before an I2CREAD, instead of in the I2CREAD.
Yes it's default to 0, but this should work for all registers ...
slave_address=$A8
adc_register=0
I2CWRITE i2cdata,i2cclock,slave_address,[adc_register]
I2Cread i2cdata,i2cclock,slave_address,[data_read.Byte0, data_read.Byte1],error


hth,

Electrosolve
- 8th August 2009, 10:59
Thanks for that Darrel

Unfortunately this gives me the same result as previous. This works ok but it is only in steps of 8. Typical values from the adc are 288,280,272 etc. This means my actual resolution is only 10 bits, not 12.

The overall output is correct, with zero input I get about zero output from the adc, and for 5 volts input I get about 4000 out.

I'll have another look at the data sheet. I don't think this is a PBP problem but I would welcome any suggestions.

Thanks

RS