public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] SOFT_I2C on at91rm9200 - FIXED
@ 2007-06-19 11:52 Nils Gjerdevik
  2007-06-19 12:35 ` Joakim Tjernlund
  0 siblings, 1 reply; 3+ messages in thread
From: Nils Gjerdevik @ 2007-06-19 11:52 UTC (permalink / raw)
  To: u-boot

2007/6/18, Matteo Vit <matteo.vit@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot-Users] SOFT_I2C on at91rm9200 - FIXED
  2007-06-19 11:52 [U-Boot-Users] SOFT_I2C on at91rm9200 - FIXED Nils Gjerdevik
@ 2007-06-19 12:35 ` Joakim Tjernlund
  2007-06-19 13:38   ` Nils N. Gjerdevik
  0 siblings, 1 reply; 3+ messages in thread
From: Joakim Tjernlund @ 2007-06-19 12:35 UTC (permalink / raw)
  To: u-boot

On Tue, 2007-06-19 at 13:52 +0200, Nils Gjerdevik wrote:
> 2007/6/18, Matteo Vit <matteo.vit@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:

Did you try my patch also and did it work?

 Jocke

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot-Users] SOFT_I2C on at91rm9200 - FIXED
  2007-06-19 12:35 ` Joakim Tjernlund
@ 2007-06-19 13:38   ` Nils N. Gjerdevik
  0 siblings, 0 replies; 3+ messages in thread
From: Nils N. Gjerdevik @ 2007-06-19 13:38 UTC (permalink / raw)
  To: u-boot

Joakim Tjernlund wrote:
> On Tue, 2007-06-19 at 13:52 +0200, Nils Gjerdevik wrote:
>   
>> 2007/6/18, Matteo Vit <matteo.vit@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:
>>     
>
> Did you try my patch also and did it work?
>
>  Jocke
>   
I've tested it both with and without your patch, and both cases worked 
for me. I've only tested that I can read and write the eeprom 
successfully, I haven't done any more in depth tests.

    Nils

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-19 13:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-19 11:52 [U-Boot-Users] SOFT_I2C on at91rm9200 - FIXED Nils Gjerdevik
2007-06-19 12:35 ` Joakim Tjernlund
2007-06-19 13:38   ` Nils N. Gjerdevik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox