5 Replies Latest reply on Mar 23, 2016 1:13 PM by JoMe_264151

    PSOC 5 I2C I2C_MasterWriteBuf function help

    userc_40334

      I have a few questions I have the I2C EEPROM I am battling with. One of the specifics of this one the EEPROM will NAK all the write attempts after a large write has been completed previously. I am using function I2C_MasterWriteBuf to write the data. I do know the write attempt is being NAKed. However I2C_MasterWriteBuf  does not return I2C_MSTR_ERR_LB_NAK in that instance. The function returns zero. I went into the source for I2C_MasterWriteBuf and could not find anywhere where it would return a NAK related result. Is it supposed to return a I2C_MSTR_ERR_LB_NAK? Documentation certainly implies so. That would be handy feature.

         

      Now for my application I do not want to place a fixed delay for EEPROM writes instead I want to keep trying to write until I get an ACK. Is there any way to do that besides manual start, send byte, send stop functions?

        • 1. Re: PSOC 5 I2C I2C_MasterWriteBuf function help
          JoMe_264151

          Welcome in the forum, Aleksey!

             

          I am not quite sure with your EEProm, but afaIk the master has to send a NAK when the multi-byte transfer is finished.Can you provide a link to your EEProm's datasheet?

             

           

             

          Bob

          • 2. Re: PSOC 5 I2C I2C_MasterWriteBuf function help
            userc_40334

            EEPROM Device is http://ww1.microchip.com/downloads/en/DeviceDoc/21941B.pdf Microchip 24LC1025. The reason it will NAK my consequent write attempts is because it needs time to process previous page write and transfer data from buffer to the actual memory. So the good people from Microchip suggest what they call an "ACK polling", which is precisely what I was trying to accomplish with I2C_MSTR_ERR_LB_NAK and I2C_MasterWriteBuf function.

            • 3. Re: PSOC 5 I2C I2C_MasterWriteBuf function help
              JoMe_264151

              EEProm specs differ a bit from your description, can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
              Creator->File->Create Workspace Bundle (minimal)
              and attach the resulting file.

                 

               

                 

              Bob

              • 4. Re: PSOC 5 I2C I2C_MasterWriteBuf function help
                userc_40334

                Bob,

                   

                I cannot share the whole project. I will share only the function I think should work. About EEPROM - don't worry if I described it incorrectly. I think my question is not really about making it work with this EEPROM, but about making it work at all.

                   

                In principal, will MasterWriteBuf return an NAK related error? 

                   

                At this point I have pretty much verified with logic analyzer that this code does not work, because I am being NAKed while sending an address to EEPROM after a long write. 25ms delay fixes it. I have also dug around in the generated BSP I2C_Master.c and everything I can find tells me that MasterWriteBuf will not return NAK related anything. Through debugging I know the only thing function returns is 0 even though the complete buffer send is aborted after write request. See attached logic analyzer. Am I correct?

                   

                 

                   

                void WriteMC(uint16 value, uint16 MC){
                    uint8 buffer[4]={(MC>>8),(MC&0xFF),(value>>8),(value&0xFF)};
                    uint8 i,n;
                    for (i=0; (i<150)&& ((I2C_1_MasterStatus()&I2C_1_MSTAT_XFER_INP)); i++){//if the transfer not in progress, if it is wait up to 150ms
                        CyDelay(1);
                    }
                    do{
                        n=I2C_1_MasterWriteBuf(Prom_Address, buffer, 4, I2C_1_MODE_COMPLETE_XFER);
                    }
                    while (n!=I2C_1_MSTR_NO_ERROR);
                    CyDelay(25);

                   

                }

                   

                 

                   

                • 5. Re: PSOC 5 I2C I2C_MasterWriteBuf function help
                  JoMe_264151

                  For checking if a NAK was sent you should use I2C_MasterWriteByte. Keep in mind that you have to issue the SendStart() and SendStop() yourself.

                     

                   

                     

                  Bob