Dear all, I'm the first time at this group. I tried the axis example, but I could not use the original ports, because the mmc card is there connected. So I used OG4 and IOG16. But I got only the message "Nack". I changed it in the c-file to 1<<4; 1<<16; Why doesn't used a pullup resistor for SCK (I2C-Clock)?? Can I use the original pins for I2C (port PB0 and PB1)?
Thanks for your help. Frank --- In [email protected], Matteo <[EMAIL PROTECTED]> wrote: > > Hi all, > > I already broken my head with i2c bit banging mode time ago, whithout the > phrozen patch (because I hadn't when I wrote my code) > > If you are interested to, I'll post here the code needed to write to/read > from the PCF8591 and PCF8574 > Please note that I've used a custom type for storing the A/D converter > values, a stupid typedef with 4 unsigned chars inside named vect4d. > > It works with the functions you can find on the user space bit banging > method tutorial... > I can assure you that it works because I'm actually using it :) > > vect4d ADConRead(unsigned char addr) { > unsigned char address; /* Base address: 1001 000X */ > vect4d temp; > address = addr; > i2c_start(); > if (i2c_outbyte(address)==0) { > //printf("NACK received %d\n",__LINE__); > i2c_stop(); > } > > if (i2c_outbyte(4)==0) { > //printf("NACK received %d\n",__LINE__); > i2c_stop(); > } > i2c_stop(); > > // Read the A/D value > > i2c_start(); > if (i2c_outbyte(address+1)==0) { > //printf("NACK received %d\n",__LINE__); > i2c_stop(); > } > > i2c_inbyte2(0); // Last conversion result > temp.val1=i2c_inbyte2(0); // Current conversion result > temp.val2=i2c_inbyte2(0); > temp.val3=i2c_inbyte2(0); > temp.val4=i2c_inbyte2(1); > > i2c_stop(); > > > return temp; > } > > /* Write values on a I/O Expander: */ > int IOExpWrite(unsigned char address, unsigned char pattern) { > unsigned char o_byte = 112; > i2c_stop(); > i2c_start(); > > o_byte = devices[address].slaveadd; > if (i2c_outbyte(pattern)==0) return -1; > i2c_stop(); > > return 1; > } > > /* Read values from a I/O Expander: */ > unsigned char IOExpRead(unsigned char address) { > unsigned char o_byte = 112; > unsigned char i_byte; > i2c_stop(); > i2c_start(); > > o_byte = address; > if (i2c_outbyte(o_byte)==0) printf("NACK !! --"); > i_byte = i2c_inbyte(); > i2c_stop(); > > return i_byte; > } >
