cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 5, 3 & 1

docn_292601
New Contributor II

1.  i call the function  I2C_M_Start();

   

2.  write a data buf to eeprom:

   

          I2C_M_MasterWriteBuf(SLAVE_ADDR, buf, num, I2C_M_MODE_COMPLETE_XFER);
           
            /* Wait till write operation is complete*/
            while (!(I2C_M_MasterStatus() & I2C_M_MSTAT_WR_CMPLT))
            {
                ;
            }

   

            //the buf includes the address of eeprom memory.

   

3. write another data buf to eeprom:

   

            I2C_M_MasterWriteBuf(SLAVE_ADDR, anotherbuf, num1, I2C_M_MODE_COMPLETE_XFER);
           
            /* Wait till write operation is complete*/
            while (!(I2C_M_MasterStatus() & I2C_M_MSTAT_WR_CMPLT))
            {
                ;
            }

   

4.  i call the function  I2C_M_Stopt();

   

my question :

   

2 worked     3 did not work

   

when i commented 2,  the 3 woked.

   

maybe  i was wrong about the mode(now is I2C_M_MODE_COMPLETE_XFER).

0 Likes
8 Replies
Bob_Marlowe
Expert II

You should at least check the returned value of the MasterWriteBuf() to see if it completed without an error.

   

 

   

Bob

0 Likes
HeLi_263931
Honored Contributor II

Your EEPROM needs additional time to finish its write. I2C_M_MasterStatus() only waits for the I2C-transfer to be finished - but writing the EEPROM will take more time. And when you try to write too soon, you will get an error.

   

E.g. see the data sheet for a 24LC1025 (http://ww1.microchip.com/downloads/en/DeviceDoc/21941K.pdf ) page 11 for an example. What device are you using?

0 Likes
ETRO_SSN583
Esteemed Contributor

Onchip EEPROM takes worst case 20 mS to write a row/block,

   

and is a blocking function when called, so I2C after fill of buffer

   

to be written, has to be stopped from further buffer activity until

   

buffer is completely written to EEPROM.

   

 

   

If you right click EEPROM, find example project, there is one you can

   

add to your design or open in a new deisgn window.

   

 

   

Regards, Dana.

0 Likes
docn_292601
New Contributor II

my eeprom device is M24256.

   

  i added  CyDelay(50) between 2 and 3.

   

the  3  worked.

   

thank you all very much.

   

谢谢!!!(my english is poor .)

0 Likes
docn_292601
New Contributor II

   

   

i find  the content above in the datasheet.

   

so i can change CyDelay(50) to CyDelay(10).

   

am i right ? i will test next.

0 Likes
HeLi_263931
Honored Contributor II

You should poll the EEPROM to find out whether it has finished writing or not. See page 18 in the data sheet (http://www.st.com/web/en/resource/technical/document/datasheet/CD00001891.pdf )

0 Likes
docn_292601
New Contributor II

oh, i see two ways:

   

1. polling the EEPROM to make sure that the sencod buf can be written.

   

2. just Call CyDelay(ms>MAX).

   

the first must be right  , the second now i use maybe right.

   

thanks.

0 Likes
docn_292601
New Contributor II

oh, i see two ways:

   

1. polling the EEPROM to make sure that the sencod buf can be written.

   

2. just Call CyDelay(ms>MAX).

   

the first must be right  , the second now i use maybe right.

   

thanks.

0 Likes