
Hi, I'm trying to store the u-boot environment in an EEPROM (at24c128) on a custom at91rm9200 based board. This fails when using the included HARD_I2C driver, and since there are known problems with the I2C controller on this uC, I'm trying to set up SOFT_I2C instead, without success so far... This is what I've put in my config file:
#define I2C_INIT \ do { \ *AT91C_PIOA_PER = AT91C_PA25_TWD | AT91C_PA26_TWCK; \ *AT91C_PIOA_ODR = AT91C_PA25_TWD; \ *AT91C_PIOA_OER = AT91C_PA26_TWCK; \ }while(0)
#define I2C_ACTIVE (*AT91C_PIOA_OER = AT91C_PA25_TWD)
#define I2C_TRISTATE (*AT91C_PIOA_ODR = AT91C_PA25_TWD)
#define I2C_READ ((*AT91C_PIOA_PDSR & AT91C_PA25_TWD) != 0)
#define I2C_SDA(bit) \ if(bit) { \ *AT91C_PIOA_SODR = AT91C_PA25_TWD; \ } else { \ *AT91C_PIOA_CODR = AT91C_PA25_TWD; \ }
#define I2C_SCL(bit) \ if(bit) { \ *AT91C_PIOA_SODR = AT91C_PA26_TWCK; \ } else { \ *AT91C_PIOA_CODR = AT91C_PA26_TWCK; \ }
#define I2C_DELAY udelay(5)
Can anyone see what's wrong with this code? I can access the EEPROM without problems in Linux, using the bit-banging driver, so the board design should be OK. The code above is(loosely) based on the Linux bit-banging driver.
Regards, Nils