6 Replies Latest reply on Sep 28, 2015 10:02 AM by user_473986618

    Problem porting working I2C from PSoC4 to 5LP

    user_473986618

      I am having a problem converting code that runs on a PSOC4 to PSOC5LP. The code is a used to drive an I2C 128x64 OLED using the great work done by Derk Steggewentz. He took the time to port over the Adafruit graphic code to work on PSoC4.

         

      The code works very well using the CY8CKIT-049 4200 Prototyping Kit. The exact code is located at:  github.com/derkst/Cypress-PSOC-OLED.  On the converted code for the PSoC5LP. I get random pixels.

         

      Here are the steps I used to move the code to the 5LP on a CY8CKIT-059 PSoC 5LP Prototyping Kit:

         

      1. Start with working project directly from   "github.com/derkst/Cypress-PSOC-OLED". It works right out of the box on the 049 kit.

         

      2. Recompile with the new device: CY8C5868LTI-LP039, (I am using the PROG KIT portion of the 059 kit).

         

      3. The PSoC4 I2C SCB component is not supported on the 5LP device, so I delete the I2C component and drag in a I2C UDB that is compatible with the 5LP.

         

      4. Assign pins to 12.2 and 12.4 (Doesn't seem to matter what pins I use).

         

      5. When I compile the code, there are a few errors as per the attached screen shot. Maybe this is the issue, but I remove the “I2C” prefix from the values that are highlighted and I get a clean compile.

         

      6. After I recompile, I try to run the code and I get random pixels on the display. This means I wired it correct and the I2C address is correct, but the data is getting garbled.

         

      7. I connected a Logic analyzer and see a difference in the starting Write frame - see attached screen shots. In the working frame, the first byte is '0x00'. On the upgraded code, the byte is '0x80'. I tried going through the I2C code, but can’t make out what needs to change to get the correct values.

         

      Hoping that someone more experienced with I2C UDB can point out my mistake. By the way, I tried a Fixed Function block and got the same results.

         

      Thanks in advance for any insight.

        • 1. Re: Problem porting working I2C from PSoC4 to 5LP
          user_242978793

          Can you download your program? We can then look at it and see what is going on.

          • 2. Re: Problem porting working I2C from PSoC4 to 5LP
            user_473986618

            I made an Archive of the 5LP project that is failing. I hope this is what you can use. If not, please let me know.

               

            Regards,

               

            Andy

            • 3. Re: Problem porting working I2C from PSoC4 to 5LP
              user_473986618

              I think I see the problem. The buffer size for the 128x64 OLED is defined as 1024 bytes.

                 

               In PSoC4 the I2C SCB Master functions allow a 32 bit data length as follows:

                 

                      uint32 I2COLED_I2CMasterWriteBuf(uint32 slaveAddress, uint8 * wrData, uint32 cnt, uint32 mode)

                 

              In PSoC5 the I2C UDB/FF Master functions only support 8bit data length:

                 

              uint8 I2COLED_MasterWriteBuf(uint8 slaveAddress, uint8 * wrData, uint8 cnt, uint8 mode)

                 

               Obviously you can't send 1024 byes in one write. Wonder why there is a difference? 

              • 4. Re: Problem porting working I2C from PSoC4 to 5LP
                user_473986618

                Follow up - Fixed it!

                   

                By making the following changes, the OLED now displays everything properly.

                   

                I manually changed the generated code variables and functions parameters from 8 bits to 32 bits for the length and index pointer. 

                   

                Note that I named my I2C UDB to "I2COLED". Your generated code will vary according to the name you gave it - default is 'I2C_1'.

                   

                Here are the generated variables:

                   

                    extern volatile uint8 * I2COLED_mstrWrBufPtr;   /* Pointer to Master Write buffer */
                    extern volatile uint8   I2COLED_mstrWrBufSize;  /* Master Write buffer size       */
                    extern volatile uint8   I2COLED_mstrWrBufIndex; /* Master Write buffer Index      */

                   

                I changed them as follows:

                   

                 extern volatile uint8 * I2COLED_mstrWrBufPtr;   /* Pointer to Master Write buffer */
                 extern volatile uint32   I2COLED_mstrWrBufSize;  /* Master Write buffer size       */
                 extern volatile uint32   I2COLED_mstrWrBufIndex; /* Master Write buffer Index      */

                   

                I also had to change the prototype and function definition:

                   

                generated = uint8 I2COLED_MasterWriteBuf(uint8 slaveAddress, uint8 * wrData, uint8 cnt, uint8 mode)

                   

                modified = uint32 I2COLED_MasterWriteBuf(uint32 slaveAddress, uint8 * wrData, uint32 cnt, uint32 mode)

                   

                Don't really need 32 bits in all of them, but these now match the PSoC4 SCB values.

                   

                Cypress should change this code and the datasheet to match the PSOC4 version so we won't have to do this manually.

                • 5. Re: Problem porting working I2C from PSoC4 to 5LP
                  user_14586677

                  You might file a CASE and point to this thread suggesting Cypress

                     

                  make these changes.

                     

                   

                     

                  To create a technical or issue case at Cypress -

                     

                   

                     

                  www.cypress.com

                     

                  “Design Support”

                     

                  “Create a Support Case”

                     

                   

                     

                  You have to be registered on Cypress web site first.

                     

                   

                     

                  Regards, Dana.

                  • 6. Re: Problem porting working I2C from PSoC4 to 5LP
                    user_473986618

                    Thanks Dana, I created a MyCase 

                       

                    3006338219