3 Replies Latest reply on Jul 4, 2018 5:05 AM by user_1_2651671

    CapSense_Start() AND EZI2C Buffer read conflict

    user_1_2651671

      Hello,

       

      I have one simple programm see attached "main1.c" that works properly, respectively I can read with Master the EZI2C-Buffer without problems:

       

      But than I have a second program with a little bit more code "main2.c" but in fact the same  - and there I cannot read the EZI2C-Buffer.

      I only get always 0 values, except I stop CapSense before give a Value to the buffer.

       

      I am very confused, and I don't know, see why with main1.c it works but with main2.c it not works??

       

      It would be very appreciate if anybody could help or point me to an solution....?

      thank you very much

       

       

       

       

      main1.c

      #include "project.h"

       

      uint8 reg[20]={0};

      uint8 diff=0;

       

       

      int main(void)

      {

          CyGlobalIntEnable; /* Enable global interrupts. */

       

          /* Place your initialization/startup code here (e.g. MyInst_Start()) */

       

       

         

          EZI2C_EzI2CSetBuffer1(sizeof(reg), 1, (uint8 *)&reg);

          EZI2C_Start();

         

          CapSense_Start();

          CapSense_ScanAllWidgets();

          while(CapSense_IsBusy()){}

          CapSense_InitializeAllBaselines();

         

          for(;;)

          {       

              /* Place your application code here. */

              CapSense_ScanAllWidgets();

       

       

              while(CapSense_IsBusy()){}

              CapSense_ProcessAllWidgets();

              diff=CapSense_BUTTON0_SNS0_DIFF_VALUE;

             

             

              Pin_1_Write(1u);

              //Pin_2_Write(1u);

              CyDelay(1u);

              Pin_1_Write(0u);

              //Pin_2_Write(0u);

              CyDelay(1u);

             

              //CyDelay(1000u);

              //CapSense_Stop();       

              reg[1]=diff;

              //CapSense_Start();

          }

      }

       

       

      /* [] END OF FILE */

       

       

      main2.c (based on example CE210291_CapSense_P4_One_Button01)

       

      int main()

       

       

      ....

          /* Start EZI2C block */

         

          EZI2C1_EzI2CSetBuffer1(sizeof(reg), 1, (uint8 *)&reg);

          EZI2C1_Start();

      ....

          CapSense_Start();

         

      ...

          WDT_Start();

         

          for(;;)

          {

              /* Switch between sensor-scan -> wait-for-scan -> process -> sleep states */

              switch(currentState)

              {

                  case SENSOR_SCAN:

                              ...

                          /* Scan widget configured by CSDSetupWidgetExt API */

                          CapSense_CSDSetupWidgetExt(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS0_ID);

                          CapSense_CSDScanExt();

                          while(CapSense_IsBusy());

                          CapSense_CSDSetupWidgetExt(CapSense_BUTTON1_WDGT_ID, CapSense_BUTTON1_SNS0_ID);

                          CapSense_CSDScanExt();

                          while(CapSense_IsBusy());

                          ....

                          .....

                      break;

       

       

                  case WAIT_FOR_SCAN_COMPLETE:

                    ...

                      break;

                 

                  case PROCESS_DATA:

                      interrupt_Write(0u);

                      /* Set next state to SLEEP */

                      currentState = SLEEP;

                     

                      /* process button widget */

                      CapSense_ProcessWidget(CapSense_BUTTON0_WDGT_ID);

                      CapSense_ProcessWidget(CapSense_BUTTON1_WDGT_ID);

                         ....

                     

                          if( counts < CapSense_BUTTON0_SNS0_DIFF_VALUE)

                          {counts = CapSense_BUTTON0_SNS0_DIFF_VALUE; button = 0;}

                     

                          if( counts < CapSense_BUTTON1_SNS0_DIFF_VALUE)

                          {counts = CapSense_BUTTON1_SNS0_DIFF_VALUE; button = 1;}

                         

                          if( counts < CapSense_BUTTON2_SNS0_DIFF_VALUE)

                          {counts = CapSense_BUTTON2_SNS0_DIFF_VALUE; button = 2;}

       

                          ....

                          ...

       

                         

                          if( counts < 11)

                          {button = 10;}

                          //else{interrupt_Write(0u);}

                         

                          //CapSense_Stop();

                          //while(CapSense_IsBusy()){}

                         

                          if(button == 0)     {reg[9]=1; Pin_1_Write(0u); Pin_2_Write(1u); Pin_3_Write(1u); Pin_4_Write(1u); Pin_5_Write(1u); Pin_6_Write(1u); Pin_7_Write(1u);                     Pin_8_Write(1u); counts=10;}

                          else if(button == 1){reg[9]=2; Pin_2_Write(0u); Pin_1_Write(1u); Pin_3_Write(1u); Pin_4_Write(1u); Pin_5_Write(1u); Pin_6_Write(1u); Pin_7_Write(1u);                         Pin_8_Write(1u); counts=10;}

                          else if(button == 2){reg[9]=3; Pin_3_Write(0u); Pin_1_Write(1u); Pin_2_Write(1u); Pin_4_Write(1u); Pin_5_Write(1u); Pin_6_Write(1u); Pin_7_Write(1u);                     Pin_8_Write(1u); counts=10;}

                          ....

                          ...

                              ...

                          else if(button == 10){reg[9]=0; Pin_1_Write(1u); Pin_2_Write(1u); Pin_3_Write(1u); Pin_4_Write(1u); Pin_5_Write(1u); Pin_6_Write(1u); Pin_7_Write(1u);                     Pin_8_Write(1u); counts=10;}

       

                          //CapSense_Start();

                         

                ...

                      break;

                     

                  case SLEEP:

                ...

                      break;

              }

          } 

      }   

       

      *******************************************************************************/

      void EnterDeepSleepLowPowerMode(void)

      {

          /* EZI2C_Sleep routine should be called only after on-going I2C

          *  transaction is complete

          *  Enter critical section to lock slave state

          */

          interruptState = CyEnterCriticalSection();

         

          /* Check if I2C is busy. If so, skip deep sleep until I2C is free */

          if(!(EZI2C1_EzI2CGetActivity() & EZI2C_EZI2C_STATUS_BUSY))

          {

              /* Configure slave to be wakeup source */

              EZI2C1_Sleep();

             

              /* Enter DeepSleep. */

              CySysPmDeepSleep();

            

              /* WDT or any I2C communication wakes up device from deep sleep. */

       

       

              /* Configure slave for active mode operation */

              EZI2C1_Wakeup();

          }

          /* Enable interrupts */

          CyExitCriticalSection(interruptState);

      }

      ....

        • 1. Re: CapSense_Start() AND EZI2C Buffer read conflict
          rzzh

          Hi Pierre,

           

          To reproduce the issue, I copied and pasted main2.c in my project, but there are some errors in the code and built failed.

          Could you share your full project here? You can right-click the project name in Creator workspace explorer, choose Archive Workspace/Project, then check "Compress Archive(zip)", "Minimal" in the pop-up window. then click Archive.

           

          Regarding the code, you can try to use "CapSense_ScanAllWidgets;while(CapSense_IsBusy()){}" to replace:"

                              /* Scan widget configured by CSDSetupWidgetExt API */

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON1_WDGT_ID, CapSense_BUTTON1_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON2_WDGT_ID, CapSense_BUTTON2_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON3_WDGT_ID, CapSense_BUTTON3_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON4_WDGT_ID, CapSense_BUTTON4_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON5_WDGT_ID, CapSense_BUTTON5_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON6_WDGT_ID, CapSense_BUTTON6_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

                            

                              CapSense_CSDSetupWidgetExt(CapSense_BUTTON7_WDGT_ID, CapSense_BUTTON7_SNS0_ID);

                              CapSense_CSDScanExt();

                              while(CapSense_IsBusy());

          "

          Use "CapSense_ProcessAllWidgets()" to replace

          "

                          CapSense_ProcessWidget(CapSense_BUTTON0_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON1_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON2_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON3_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON4_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON5_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON6_WDGT_ID);

                          CapSense_ProcessWidget(CapSense_BUTTON7_WDGT_ID);

          "

           

          And I just went through the logic to control LEDs, but I'm not very clear about it. The variable 'counts' is used for what?

          And can try give some value to 'reg[]' directly without "if else" sentence to check with using I2C master if the I2C buffer is empty or not.

           

          Thanks,

          Ryan

          • 2. Re: CapSense_Start() AND EZI2C Buffer read conflict
            user_1_2651671

            And I just went through the logic to control LEDs, but I'm not very clear about it. The variable 'counts' is used for what?

            And can try give some value to 'reg[]' directly without "if else" sentence to check with using I2C master if the I2C buffer is empty or not.

            With variable "counts" I check which "CapSense_Button Diff Value" is the highest and than I switch the corresponding Button-LED On and the other 7 Button LED's Off (total 8x CapSense_Buttons).

             

            Please find attached the whole project, it's for the Evalkit (4045).

            With CapSense_Stop before writing to reg[], it works - but without it not works (I can only read 0 values)!

             

            EDIT:

            And can try give some value to 'reg[]' directly without "if else" sentence

             

            that doesn't matter, still the same problem.

            • 3. Re: CapSense_Start() AND EZI2C Buffer read conflict
              user_1_2651671

              I have found the problem:

               

              I should not send a write-command with 0x00 data to Slave before reading the buffer.

              So now I'm only reading the buffer without write-command before.

               

              the only confusing thing for me now is: Why does it have works with main1.c but not with main2.c??

               

              thank you very much