12 Replies Latest reply on Dec 8, 2014 12:32 AM by MoHa_301381

    problem with I2Cm



            I am trying to interface i2c EEPROM and RTC (24LC512 from Microchip and DS1307)  CY8C28452,


      i am using I2Cm module and configure P2_7 as SDA and  P2_6 as SCL. also configure pin as OPEN DRAIN LOW and pull up the pins with 4K7 E resistor.


          i use the source code provided in data sheet. but it not works. i check with CRO their is no pulsing on P2_7 as SDA and  P2_6 as SCL. then i change pull up  to 2k2 but still same thing.also i try with only RTC on board but no op my disply show me error.


      i used system clk 24Mhz and CPU clk  system clk / 2.


      please help me

        • 1. Re: problem with I2Cm



             please find attachment for detail.

          • 2. Re: problem with I2Cm

            Do not use chrome when uploading any attachments, it will not work, use ie or firefox, they will.


            Best would be when you attach the complete project, so we all can have a look at. Use Designer, File -> Archive Project and attach the resulting .zip archieve here.





            • 3. Re: problem with I2Cm

              The ports get set up for you, from datasheet -




              Selects which PSoC I/O port is used to interface the SDA and SCL signals.


              Selects which pin of the I2C_Port, the SDA data signal will be present. There is no need to select the proper drive mode for this pin; PSoC Designer will do this automatically.


              Selects which pin of the I2C_Port, the SCL Clock signal will be present. There is no need to select the proper drive mode for this pin; PSoC designer will do this automatically.

              • 4. Re: problem with I2Cm

                This is key if I2Cm is using port with other I/O -




                Direct writes to the PORT used by the I2Cm User Module will interfere with I2C operation. A shadow register is automatically added for the port used by the I2Cm User Module. For example, if Port1 is used by the module, a shadow register named Port_1_DriveMode_0_SHADE is added to the project. All writes to Port1 should be done using this shadow register. For example, if Port1 bits 5 and 7 are used by the I2Cm User Module, a modification to port pin 6 could be made as follows:




                C code:

                Port_1_DriveMode_0_SHADE ^= 0x40;
                PRT1DR = Port_1_DriveMode_0_SHADE;
                • 5. Re: problem with I2Cm



                     please find attachment for detail.

                  • 6. Re: problem with I2Cm



                       As i am trying to attach the file it's not done. so here is the code.


                    system clk 24Mhz and CPU clk  system clk / 2.



                         I2C_Port 2   

                    SDA_Pin P2_7  OPEN DRAIN LOW with 2k2 external Pullup 


                    SCL_Pin  P2_6  OPEN DRAIN LOW with 2k2 external Pullup 








                    // C main line  new




                    #include <m8c.h>        // part specific constants and macros


                    #include "PSoCAPI.h"    // PSoC API definitions for all User Modules


                    //#include "psocdynamic.h" 




                    void Display(void);






                    BYTE rxBuf[8];


                    const BYTE txCBuf[] = { 0x00, // Slave internal sub-address 0


                     0x12,0x34,0x08, // Seconds and minutes in BCD 


                    // 8:34:12am


                     0x01, // Day of Week, Monday 


                     0x15,0x03,0x02, // Day-Month-year 15-Mar-02


                     0x90 }; // Enable clock output




                    #define DISP_MASK 0xF0






                    // Alphabetic Segment Pattern  




                    #define _A_ 0x88


                    #define _b_ 0x83


                    #define _c_ 0xA7


                    #define _d_ 0xA1


                    #define _E_ 0x86


                    #define _F_ 0x8E


                    #define _g_ 0x90  


                    #define _h_ 0x8B


                    #define _i_ 0xFB


                    #define _J_ 0xF1


                    #define _K_ 0x85


                    #define _L_ 0xC7


                    #define _M_ 0xAA


                    #define _n_ 0xAB


                    #define _o_ 0xA3


                    #define _P_ 0x8C


                    #define _q_ 0x98


                    #define _r_ 0xAF


                    #define _S_ 0x92


                    #define _t_ 0x87


                    #define _u_ 0xE3


                    #define _V_ 0xC1


                    #define _W_ 0x95


                    #define _X_ 0x89


                    #define _y_ 0x91


                    #define _Z_ 0xA4   




                    // Number Segment Pattern  






                    #define _0_     0xc0


                    #define _1_     0xf9


                    #define _2_     0xa4


                    #define _3_     0xb0


                    #define _4_     0x99


                    #define _5_     0x92


                    #define _6_     0x82


                    #define _7_     0xf8


                    #define _8_     0x80


                    #define _9_     0x90






                    // Special charaters Segment Pattern  




                    #define _HYFAN_  0xBF


                    #define _Ne_VE_  _HYFAN_


                    #define _BLANK_   0xFF


                    #define _ALL_ON_  0x00


                    #define _DPT_     0x7F




                    const unsigned char number_code[10] = {_0_,_1_,_2_,_3_,_4_,_5_,_6_,_7_,_8_,_9_};//7_seg










                    BOOL toggle;


                    unsigned char Val2Disp,Dispcode,DispBuf[9],key_press;


                    unsigned int KeyCount;


                    long signed int Count;




                    // PWM ISR 




                    #pragma interrupt_handler housekeeping


                    void housekeeping(void)




                    static unsigned int  dispsel,TimeTick1msec;




                    PRT2DR |= 0x2f;     //disable display drives  


                    PRT1DR = 0xFF;      //disable all seven segment displays 


                    PRT1DM0 = 0xff;     //make port input


                    PRT1DM1 = 0xff;  


                    key_press = PRT1DR;








                       //DispBuf[8] &= 0x01;






                          {KeyCount = 0;}//DispBuf[8] &= 0x02;  




                     PRT1DM0 = 0xff;                 //make port output


                          PRT1DM1 = 0x00;


                     PRT2DR &= DISP_MASK;          // Change Display 


                     PRT2DR |= dispsel;            // Change Display 


                       PRT1DR = DispBuf[dispsel];      //DispBuf[dispsel]


                     dispsel = (dispsel + 1) & 0x0F; // Incriment Display Selection *






                    // Main Routine




                    void main(void)



                       BYTE status; // I2C communication status


                       BYTE i; // Temp counter variable






                       I2Cm_Start(); // Initialize I2C Master interface


                       // Set the time


                       status = I2Cm_bWriteCBytes(0x68,txCBuf,9,I2Cm_CompleteXfer);






                       M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO);   // C code to enable GPIO interrupt


                       RES_WDT = 0x38;   








                           RES_WDT = 0x38;


                      // In a endless loop, keep reading the time from the DS1307


                           do {


                              // Write sub-address to DS1307


                              // Perform a combined transfer by leaving off the Stop on the Write


                              // command and beginning the Read with a Repeat Start.


                              I2Cm_bWriteCBytes(0x68,txCBuf,1,I2Cm_NoStop ); 


                              status = I2Cm_fReadBytes(0x68,rxBuf,7,I2Cm_RepStart ); 


                              if(status == 0)




                                rxBuf[i] = 251;// Flag an error condition




                               // This next section of code performs exactly the same sequence


                               // as the above code, but with low level commands.


                               I2Cm_fSendStart(0x68,I2Cm_WRITE); // Do a write


                               I2Cm_fWrite(0x00); // Set sub address 


                               // to zero


                               I2Cm_fSendRepeatStart(0x68,I2Cm_READ); // Do a read


                               for(i = 0; i < 6; i++) {


                               rxBuf[i] = I2Cm_bRead(I2Cm_ACKslave); // Read first 6 bytes,


                               // and ACK the slave




                     rxBuf[7] = I2Cm_bRead(I2Cm_NAKslave); // Read data byte and


                    // NAK the slave to signify


                    // end of read.






                     } while(1);












                    void Display(void)




                    unsigned int dummyvalue2display;


                    unsigned char handle;




                    dummyvalue2display = rxBuf[3];


                      for(handle = 0;handle <= 7;handle ++)




                     DispBuf[handle] = number_code[dummyvalue2display % 10];







                    • 7. Re: problem with I2Cm

                      Sorry, but as the code only shows half the project (NO settings, no modules) I cannot step through it. Try using internet explorer when attaching a project archive, this WILL work.





                      • 8. Re: problem with I2Cm



                            thanks to all for valuable suggestion.


                        Specially  Danaaknight


                        i use SHADE REG to change value of port 2 ,that solved my problem.


                        thank you againg Danaaknight

                        • 9. Re: problem with I2Cm

                          Hi every body!
                          I'm doing a project to test I2C communication between PSoC 1 CY8C24123A and RTC DS1307.
                          I'm using I2Cm (P1.1 SCL, P1.0 SDA) and TX8 (P0.5, baud rate 9600) user modules.
                          SCL and SDA pulled up VCC (5V) by resistor 1.5k.
                          I want use TX8 module to send data of register 0x00 - 0x07 (from DS1307) to PC via RS232 circuit.
                          Link refer:
                          But my project can't work!


                          Is this problem when I combine I2Cm and TX8 (2 communications protocol)?
                          Can you please check project for me?


                          Below it is my project.
                          Many thanks!

                          • 10. Re: problem with I2Cm

                            You have no connection from your Tx8 output. Select an appropiate pin and that should work.





                            • 11. Re: problem with I2Cm

                              Thanks for your help!