PCF8591 input reads
Chicago Mike
Posts: 88
I have a few questions about reading from a PCF8591. I'm read over the datasheet several times and there are some this that I just don't get.
Below is a small bit of code I'm using to attempt to read Input 3.
I seem to always get a 128. (When I have the input pin at 3.3 volts, which is what the PCF is running at, which should result in data2 reading 255).
My questions are:
- Obviously, this type of selective read isn't working? Any tips?
- The datasheet and the nuts and volts article I read refer to having to ditch the first read value because its the 'last' value. I'm doing this with the data1 variable in this case. Is this really needed in a selective read like this?
- I don't understand the auto increment. I'm not using it here, but if I used it, would I just perform 5 reads. (The first one being junked because of the above, and then I would read the 4 inputs?
- DO I need to re issue the control byte on every read like the above, or after executing it once, can I continuously perform the following to get constant updates
-
Below is a small bit of code I'm using to attempt to read Input 3.
PUB ReadAD(SCL, devSel) | ackbit,data1,data2 Start(SCL) ackbit := (ackbit << 1) | Write(SCL, (devSel&!(|<0))) ackbit := (ackbit << 1) | Write(SCL, %00000011) Start(SCL) ackbit := (ackbit << 1) | Write(SCL, (devSel|1)) data1:=Read(SCL,ACK) data2:=Read(SCL,NAK) Stop(SCL) return data2
I seem to always get a 128. (When I have the input pin at 3.3 volts, which is what the PCF is running at, which should result in data2 reading 255).
My questions are:
- Obviously, this type of selective read isn't working? Any tips?
- The datasheet and the nuts and volts article I read refer to having to ditch the first read value because its the 'last' value. I'm doing this with the data1 variable in this case. Is this really needed in a selective read like this?
- I don't understand the auto increment. I'm not using it here, but if I used it, would I just perform 5 reads. (The first one being junked because of the above, and then I would read the 4 inputs?
- DO I need to re issue the control byte on every read like the above, or after executing it once, can I continuously perform the following to get constant updates
Start(SCL) ackbit := (ackbit << 1) | Write(SCL, (devSel|1)) data1:=Read(SCL,ACK) data2:=Read(SCL,NAK) Stop(SCL)
-
Comments
(2) After that you can read ad infinitum; you either get the values from one channel or cycling through the 4.
(3) I think there is too much ado about this "first" value... It is just the last value sampled, as the sampling process will only start with the read command and takes some time, so it MIGHT be unclear from what channel and from what time this value comes...
(4) I am not sure with what channel each new read starts in auto-incrementing mode.. I THINK it will will go on with the last channel, so it might be a good practice to repeat the configuration setting before each sequence of reads...
Heres the current code running in a loop:
My circuit
PIN = Tied to
(1-3)AIN1-AIN2 = Vss
(4)AIN3 = (Sampling input, for testing I've tied this to 3.3 volts)
(5-7)A0-A2 = Vss
(8)Vss = Vss
(9-10)SDA-SCL = I2c bus
(11)OSC = Floating
(12)EXT = Floating
(13)AGND = Vss
(14)VRef = 3.3V(Vdd)
(15)AOut = Floating
(16)Vdd = 3.3v
Very, very strange, I'm stumped. This is such a basic component.
Thanks!
If that does not work, you should check the ACKs, they should all be 0....
If not here is code that is checked with my "smallI2Cdriver":
Post Edited (deSilva) : 1/23/2008 10:26:04 PM GMT