1 2 Previous Next 21 Replies Latest reply on Feb 7, 2017 4:44 AM by user_252

    5LP as I2C Slave

    user_252

      I was reading some of the examples and thought I could make some quick progress by running a quick test but I seemed to have failed at step one.

         

       

         

      I added an EZI2C Slave module to my project and then copied the following code into my main.c:

         

       

         
          

      /* Slave address of the EZI2C */
      #define EZI2C_SLAVE_ADDR        (0x08u)
      #define BUFFER_SIZE             (0x04u)
      #define BUFFER_RW_AREA_SIZE     (0x02u)

          

      /* Denotes the offset inside the EZI2C buffer */
      #define SLAVE_ADDR_SIZE         (0x01u)

          

      /* EZI2C buffer */
      uint8   ezi2cBuffer[BUFFER_SIZE];

          

      /* I2C buffer with the data read from EZI2C */
      uint8   i2cBufferRead[BUFFER_SIZE];

          

      /* I2C buffer with the data to be written to EZI2C */
      uint8   i2cBufferWrite[SLAVE_ADDR_SIZE + BUFFER_SIZE];

          

      int main()
      {

          

      ...

          

      /* Start EZI2C */
          EZI2C_Start();
          
          /* Enable global interrupts */
          CyGlobalIntEnable;
          
          /* Initialize EZI2C buffer's read only data */
          ezi2cBuffer[BUFFER_RW_AREA_SIZE     ] = 0xAAu;
          ezi2cBuffer[BUFFER_RW_AREA_SIZE + 1u] = 0xBBu;

          

          EZI2C_SetBuffer1(BUFFER_SIZE, BUFFER_RW_AREA_SIZE, (void *) ezi2cBuffer);

         
         

       

         

      I thought this would be enough to see the 5LP on the I2C bus and even read the initial data but the 5LP doesn't show up on the bus. I have 2 other devices on the board that do show up and I can read from them so the I2C bus seems to be working.

         

      Is there something that I'm missing here?

         

       

         

      Thanks,

         

      George 

        • 1. Re: 5LP as I2C Slave
          user_1377889

          You are using three independent buffers instead of only one. The first part of the buffer is used for the master to read from and write to, the second part is for the master to only read from. the EZI2C_SetBuffer1() tells where the buffer is and where the point between read and write area lies. There is a status call that shows any activities the master has made.

             

          Next time  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. It will help (at least me) to find any problems.

             

           

             

          Bob

          • 2. Re: 5LP as I2C Slave
            user_252

            Hi Bob,

               

            Thanks for replying. That code was copied straight out of an example I2C slave project. I've attached the project for you.

               

            At this point I wasn't worried about how the buffer was defined or split between read and write boundaries. I have the board connected to a Raspberry Pi and when I issued a "sudo i2cdetect -y 1" I could see the ADC and FRAM on my board (50, 51, 54) but not the 5LP which was using the default 0x08 address. I thought maybe the built-in code didn't respond to polling so I issued a "sudo i2cget -y 1 0x08" to see if I could read the 5LP buffer and I got an error.

               

            Does there have to be explicit code written before the master can read from the slave buffer? I thought what I had written would be enough to get the initial response and prove that I had a good working starting place.

               

            Thanks,

               

            George 

            • 3. Re: 5LP as I2C Slave
              user_1377889

              ... waiting for the complete project...

                 

              Btw: Where is the FRam from? Or are you using a CY8CKIT-044 Pioneer kit?

                 

               

                 

              Bob

              • 4. Re: 5LP as I2C Slave
                user_252

                I attached the complete project to that last post. I edited the post after I submitted it and added the project so you might have missed that. It's a custom board I made which I'm attaching the schematic for your reference.

                • 5. Re: 5LP as I2C Slave
                  user_1377889

                  Try the attached project. Set the pin for the LED to an output you can measure.

                     

                   

                     

                  Bob

                  • 6. Re: 5LP as I2C Slave
                    user_252

                    Thanks Bob. I have to run to a meeting but I'll give this a try tonight and let you know what happens

                    • 7. Re: 5LP as I2C Slave
                      user_252

                      I just ran your test and when I issue the i2cdetect command on the 5LP I don't see a pulse on the LED pin which I changed to P1[7] and monitored by setting the scope to trigger on an edge. I still see the ADC and FRAM.

                      • 8. Re: 5LP as I2C Slave
                        user_1377889

                        According to your schematic you powered VDDIO0, but not VDDIO1, 2 and 3.

                           

                         

                           

                        Bob

                        • 9. Re: 5LP as I2C Slave
                          user_252

                          Wow, I see that now, talk about brain dead. But before I added the I2C code I programmed the board and had it run the HSSP code which worked. This is the 1st time using the 5LP so I'm not sure what the VDDIO1-3 rails do and why the part would seem to work even if they're not powered.

                          • 10. Re: 5LP as I2C Slave
                            user_252

                            Just looked in the datasheet and found this:

                               

                               

                            So I guess that explains why my I2C connections on P12[0-1] doesn't work. Time for some soldering of some jumper wires and re-testing!

                               

                            And I just remembered that I was able to run the code to program using HSSP when I was testing with the Dev Kit. I've never used this board to program another board and looking at my connections it won't work unless I jumper VDDIO0 to VDDIO1-3

                               

                            • 11. Re: 5LP as I2C Slave
                              user_252

                              OK, I added the jumper wires and confirmed that I'm getting 3.3V on all VDDIO0-3 pins. I still wasn't seeing 0x08 when I issued the i2cdetect command. To confirm that VDDIO3 was in fact powered I removed C9, configured P3[2] as an output, and added a toggle to P3[2] in the main section of code. I can probe P3[2] and confirm that I'm getting a square wave. 

                                 

                              So now I'm back to being stuck not knowing why the 5LP isn't responding to a i2cdetect command. I also tried "sudo i2cget -y 1 0x08 0x00 b" and I get a read error so it doesn't appear that the 5LP I2C is responding.

                                 

                              In your code I set the LED pin to P1[7] and I can see that pin toggle with each i2cdetect I detect but why would a read fail since the buffer is set up and why doesn't it appear when the i2cdetect command is run?

                              • 12. Re: 5LP as I2C Slave
                                user_252

                                I'm attaching 2 logic analyzer captures. The first one shows a successful read of the ADC on the board and the 2nd one is an attempt to read the 5LP at address 0x08 and the 5LP issuing a NAK

                                • 13. Re: 5LP as I2C Slave
                                  user_1377889

                                  Can I have your actual project? Or can you reduce the project to its barest?

                                     

                                   

                                     

                                  Bob

                                  • 14. Re: 5LP as I2C Slave
                                    user_252

                                    The logic analyzer captures are with the example project you provided. I only changed the LED pin and added the toggle on P3[2] to confirm that VDDIO3 was being powered with my jumper wire addition.

                                    1 2 Previous Next