| ??? 07/21/02 02:57 Read: times |
#26065 - RE: PCF8591 (lots of source code) |
I'll answer my own question in hopes that someone will benefit from it.
The app notes were confusing (to me), turns out I also needed to restart the I2C bus in read mode after I was finished writing to it. unsigned char ADC_read(unsigned char channel) { unsigned char idata result = 0; I2C_start(); if( !I2C_write(ADC_ID|WRITE) ) { printf("Did not get an ack from PCF8591rn"); return 0; } if( !I2C_write(ADC_CTRL|channel) ) { printf("Did not get an ack from PCF8591rn"); return 0; } I2C_start(); if ( !I2C_write(ADC_ID|READ) ) { printf("Did not get an ack from PCF8591rn"); return 0; } I2C_read(); I2C_ack(); result = I2C_read(); I2C_nack(); I2C_stop(); return result; } /* }}} */ |
| Topic | Author | Date |
| PCF8591 (lots of source code) | 01/01/70 00:00 | |
RE: PCF8591 (lots of source code) | 01/01/70 00:00 |



