Thx for the Sample, but i found the problem.
I found out,that i have some trouble with the hardware, not with the
software!
Now the problem is fixed and the code works perfect!
Thanks for your help!
MrRossi
--- In AT91SAM7@AT91..., "Larsen, Morten ActeNO"
<morten.larsen@a...> wrote:
>
> This is something I tested a year ago almost -
> but AFAICR, it works.
>
> /* "twi.c" */
>
> #include <board.h
> void twi_init(void)
> {
> // PIOA-pin setup:
> AT91F_TWI_CfgPIO();
> // clk enable:
> AT91F_TWI_CfgPMC();
> // TWI setup:
> AT91F_TWI_Configure(AT91C_BASE_TWI);
>
> // set TWI clk:
> *AT91C_TWI_CWGR = (7<<16)|(255<<8)|(255); // CKDIV | CHDIV |
CLDIV =
> 111 1111 1111
> // set dev.adr to 7-bits, adr.space to 16-bits:
> *AT91C_TWI_MMR = 0x550200;
>
> // and roll ...
> }
> void i2cMasterSend(unsigned char dev_adr, unsigned short mem_adr,
> unsigned char data)
> {
> unsigned int status;
>
> *AT91C_TWI_IADR = mem_adr;
> //
> *AT91C_TWI_MMR &= ( 0xFF00EFFF | (dev_adr<<16) );
> //
> *AT91C_TWI_CR = AT91C_TWI_START | AT91C_TWI_MSEN | AT91C_TWI_STOP;
> //
> *AT91C_TWI_THR = data;
> //
> status = *AT91C_TWI_SR;
> while ( !(status & AT91C_TWI_TXCOMP) ) {
> status = *AT91C_TWI_SR;
> }
> }
> unsigned char i2cMasterReceive(unsigned char dev_adr, unsigned short
> mem_adr)
> {
> unsigned int status;
>
> *AT91C_TWI_IADR = mem_adr;
> //
> *AT91C_TWI_MMR |= ( 0x00001000 | (dev_adr<<16) );
> //
> *AT91C_TWI_CR = AT91C_TWI_START | AT91C_TWI_MSEN | AT91C_TWI_STOP;
> //
> status = *AT91C_TWI_SR;
> while ( !(status & AT91C_TWI_TXCOMP) ) {
> status = *AT91C_TWI_SR;
> }
> //
> return (unsigned char)*AT91C_TWI_RHR;
> }
> /* "test_24c_eeprom.c" */
>
> /* "i2ceeprom_test.c" */
>
> #include <stdio.h>
> #include "twi.h"
>
> #define DEV_ADR 0 // I2C-adresse=0
> #define EEPROM_DADR (DEV_ADR | 0x50) // default-adr.bits
> [6:3]="1010"
>
> main()
> {
> unsigned char data, i=1;
> unsigned short mem_addr;
>
> // init TWI:
> twi_init();
>
> printf("\r\n***** I2C-EEPROM AT24C04 test program nr.2!
*****\r\n");
>
> while (1) {
> printf("\r\nWriting data=%d to adress=0-255\n", i);
> for (mem_addr=0; mem_addr<256; mem_addr++) {
> i2cMasterSend(EEPROM_DADR, mem_addr, i);
> putchar('.');
> }
> //
> printf("\r\nReading data from EEPROM adr.0-255 ...\n");
> for (mem_addr=0; mem_addr<256; mem_addr++) {
> data = i2cMasterReceive(EEPROM_DADR, mem_addr);
> printf("0%x ", data);
> }
>
> printf("\r\nPress ENTER for next iteration!\n");
>
> while ( !getchar() ) ;
>
> i++;
> }
> }
>
> Hope this helps
> Rgds
> Morten
>
> > -----Original Message-----
> > From: AT91SAM7@AT91...
> > [mailto:AT91SAM7@AT91...] On Behalf Of mr_rossi_1
> > Sent: Thursday, September 29, 2005 1:35 PM
> > To: AT91SAM7@AT91...
> > Subject: [AT91SAM7] AT91SAM7-64 and TWI (i2C) with FM24C64
> >
> > Hello.
> > I have some probloems with my AT91 and a fram i connected via
> > the TWI.
> > I am using the sample code from the atmel-homepage.
> > unfortunately i have some trouble with the code. I am not
> > able to read or write information into the fram. con anybody
> > give me an sample of a twi implementation?
> > thx
> > MrRossi
> >
> >
> >
> >
> >
> >
> > ------------------------ Yahoo! Groups Sponsor
> > --------------------~--> Fair play? Video games influencing
> > politics. Click and talk back!
> > http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/dN_tlB/TM
> > --------------------------
> > ------~->
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>