2 Replies Latest reply on Mar 5, 2018 5:32 AM by user_288547314

    Using interrupts with I2c slave


      I want to use I2c slave to receive requests to a very busy PSOC 5 system.  I don't want to have to poll for messages.  Looking at the I2c interrupt code generated I can see where it disables and enables I2c_ENABLE_INT_ON_STOP.  However I can see no information about where the stop interrupt handler is, or how to direct or redirect it to my own code.

      What am I missing here?

      Also, is there a better way to handle this?


      Thanks, Russ


        • 1. Re: Using interrupts with I2c slave

          At page#29 of the component datasheet, there is description about Macro callbacks which may be useful-



          • 2. Re: Using interrupts with I2c slave

            Yes, thank you. Shortly after posting I realized that answer - and implemented it.  This seems to be a superior solution - much better than implementing additional interrupts.  The user code becomes part of the I2c interrupt.


            For the benefit of others, I would like to point out that the API (and even the macro callbacks) documentation is not clear on how to do this.  For one thing it seems to imply that the CyApiCallbacks.h file should be found in the project.  In reality the user must create that file and add it to the project.  In that header file must be:



                #define I2c_HW_PREPARE_READ_BUF_CALLBACK

                void I2c_HwPrepareReadBuf_Callback ();


            If you are using software I2C then change the letters HW to SW, and Hw to Sw. 

            The documentation implies that if the callbacks.h file exists it will automatically be used.  I did not find this to be true.  In the I2c_INT.c file there is a section like:






                *  Place your includes, defines and code here.





                /* `#START UserI2c_ISR_intc` */






                /* `#END` */



            I had to add the line " #include CyApiCallbacks.h", between the START and END lines.




            The actual function definition can be placed in any of your normal c modules, or in its own file if you desire.


            The I2c_HwPrepareReadBuf_Callback function will be called immediately after the master sends the read address.  It is responsible for loading the I2c read buffer with the data to be sent when the master reads.

            Note that the read and write buffers are named with respect to how the master looks at them.  So the slave has to read the master commands from the write buffer, and send results to the read buffer.

            A final note is that the Cypress I2C slave absolutely requires that the final read call be sent with a NAK (and of course any previous reads must not have the NAK).  I have seen other slaves that do not require that, and just rely on the stop to end things.


            These are all things that can trip up a new (or sometimes even experienced) I2C programmer, and I have seen nowhere where they are spelled out in simple terms.  By including those details here I hope it will help some one.


            Thanks again - Russ




            1 of 1 people found this helpful