[U-Boot-Users] SOFT_I2C on at91rm9200 - FIXED

Nils Gjerdevik nils.gjerdevik at gmail.com
Tue Jun 19 13:52:55 CEST 2007


2007/6/18, Matteo Vit <matteo.vit at dave.eu>:
> Nils Gjerdevik ha scritto:
> > 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...

Problem solved! Turns out the peripheral clock for the pio controller
wasn't enabled. In the Linux code I looked at this was already done
elsewhere. Thanks to Joakim and Matteo for valuable help.
For the record, here is the code:

/* enable I2C */
#define	CONFIG_SOFT_I2C         1	/* I2C bit-banged		*/
#define CONFIG_I2C_CMD_TREE

#define CFG_I2C_SPEED		10000
#define CFG_I2C_SLAVE		0

//Enable peripheral clock and configure data and clock pins for pio
#define I2C_INIT { \
    *AT91C_PMC_PCER = 1 << AT91C_ID_PIOA;		\
    *AT91C_PIOA_IDR = AT91C_PA25_TWD | AT91C_PA26_TWCK;	\
    *AT91C_PIOA_MDER = AT91C_PA25_TWD | AT91C_PA26_TWCK; \
    *AT91C_PIOA_PUDR = AT91C_PA25_TWD | AT91C_PA26_TWCK; \
    *AT91C_PIOA_ODR = AT91C_PA25_TWD | AT91C_PA26_TWCK;	\
    *AT91C_PIOA_PER = AT91C_PA25_TWD | AT91C_PA26_TWCK; \
}

//Configure data pin as output
#define I2C_ACTIVE      (*AT91C_PIOA_OER = AT91C_PA25_TWD)

//Configure data pin as input
#define I2C_TRISTATE    (*AT91C_PIOA_ODR = AT91C_PA25_TWD)

//Read data pin
#define I2C_READ        (*AT91C_PIOA_PDSR & AT91C_PA25_TWD ? 1 : 0)

//Set data pin
#define I2C_SDA(bit)    *AT91C_PIOA_OER = AT91C_PA25_TWD; \
  if (bit) *AT91C_PIOA_SODR = AT91C_PA25_TWD; \
  else *AT91C_PIOA_CODR = AT91C_PA25_TWD

//Set clock pin
#define I2C_SCL(bit)    *AT91C_PIOA_OER = AT91C_PA26_TWCK; \
  if (bit) *AT91C_PIOA_SODR = AT91C_PA26_TWCK; \
  else *AT91C_PIOA_CODR = AT91C_PA26_TWCK

#define I2C_DELAY       udelay(2)      /* 1/4 I2C clock duration */


The env_in_eeprom config is:
#define CFG_ENV_IS_IN_EEPROM            1
#define CFG_ENV_OFFSET                  0          /* Env in the
beginning of EEPROM */
#define CFG_ENV_SIZE                    0x800      /* 2kb */
#define CFG_I2C_EEPROM_ADDR             0x50       /* Default EEPROM address */
#define CFG_EEPROM_PAGE_WRITE_BITS      6          /* 64 byte page size */
#define CFG_EEPROM_PAGE_WRITE_DELAY_MS  5          /* 5ms delay
between page writes */
#define CFG_I2C_EEPROM_ADDR_LEN         2          /* 2 bytes used for
addressing in the EEPROM */
#define CFG_EEPROM_SIZE                 0x4000     /* 16kb */

    Nils




More information about the U-Boot mailing list