This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Regarding I2C Interfacing in CC2530

Other Parts Discussed in Thread: CC2530, Z-STACK, REMOTI

Hello Sir,
I am referring example sample switch in HA profile on CC2530 ,for my project.There are some doubts that are taking more time to resolve.I have light sensor on board which is interfaced using I2C  protocol,I am getting its output on pin 0.6 as interrupt  ,so I configured the HalKeyConfig  for same.

My doubt is I2C protocol is not working  in Z-stack OS ,though it is working normally ,(normally when I wrote a single program).No changes in SCL

By using  I2C example given in RemoTI stack ,I am unable to get the I2C work..

Since this particular things is getting me to move ahead.Can anybody help please.

Thanks!

  • Which CC2530 pin do you use as I2C clock pin?
  • Pin P0_1 for clock pin
  • Do you change hal_i2c.c to use P0.1 as I2C clock pin?
  • yes,I did for SCL I changed it to P0_1 and for SDA to P0_0.
  • Can you show me how you change it?
  • please find the attached file.

    i2c.h

    #include "hal_board.h"
    #include "ioCC2530.h"
    #include "hal_cc8051.h"
    #include "hal_mcu.h"
    #include "hal_types.h"
    #include "stdio.h"
    #include "i2c.h"
    
    void wait()
    {
      halMcuWaitUs(200);
    }
    void start(void)
    {
      wait();
      if((!SDA) || (!SCL))
      {
        smbBUS_BLOCKED++;
      }
      D_LO(); //pull the SDA line LOW
      wait();
      CLK_LO(); //pull the clock line LOW
      wait();
      D_HI(); //pull the Data line HIGH
      wait();
    }
    void stop(void)
    {
       D_LO();
       wait();      
       CLK_HI();
       wait();   
       
       if (!SCL){ smbBUS_BLOCKED++; }
       
       D_HI();
       wait();  
       
       if (!SDA){ smbBUS_BLOCKED++; }
       halMcuWaitMs(2);// to avoid too fast stop to start condition - workaround! // 
    }
     uint8 readBit()
    {
      uint8 ack;
      
      D_HI();
      wait();  
      CLK_HI();
      wait();    
      if (!SCL){ halMcuWaitMs(10); } //clock stretching, add wait  , v5
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      
      if (!SCL)
      {smbBUS_BLOCKED++;}
      wait();//new  
      wait();//new  
      ack = SDA;
      wait();  
      CLK_LO();
      wait();    
      
      return ack;//0=ack
    }
    void writeBit(uint8 write)
    {
     CLK_LO();//new
    wait();//new  
     
      if(write > 0){ D_HI();}else{D_LO(); }
      wait();      
      CLK_HI();
      wait();        
      if (!SCL){ halMcuWaitMs(10); } //clock stretching, add wait >12ms for Si7020 stretching   
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      if (!SCL){ halMcuWaitMs(10); } 
      
      if (!SCL){ smbBUS_BLOCKED++; }
      //CLK_LO();//new
      CLK_LO();
      wait();          
    }
    
    uint8 sendByte(uint8 b)
    {
     uint8 i;
       uint8 ack;
       for (i = 0; i < 8; i++){
          smbWriteBit(b & 0x80);
          b = (b <<  1);
       }
       
       ack = !(smbReadBit() );
       return ack; //high = ACK received
    }
    
    void BIT()
    {
      if( (!SCL) || (!SDA))
      {
        smbBUS_BLOCKED++;
        printf("\nI2C Error.....\n");
        while(TRUE)
        {
          LED_R_SET();
          Buzzer(1400,100,0);
          halMcuWaitMs(100);
          Buzzer(700,100,0);
          halMcuWaitMs(100);
        }
      }
    }
    
    uint8 readByte()
    {
      uint8 byte = 0;
      uint8 i;
      for (i = 0; i < 8; i++) {
        byte = (byte << 1) | smbReadBit();
      }
      return byte;
    }
    
    void restart()
    {
      D_HI();//
      CLK_HI();//
      smbStart();//
      return;//
    
      D_LO();
      wait();
      CLK_HI();
      wait();
      D_HI();
      wait();  
      CLK_LO();
      wait();    
    
      CLK_HI();
      
      wait();    
      D_LO();
      wait();      
      CLK_LO();
      wait();
    }
    
    

  • Where is this code from? As I know, hal_i2c.c and .h from REMOTI are not like this.
  • Yes Sir I know I made this code coz it requires some bit banging,
    I want to know how to connect the I2C driver to hal driver.c

    Thanks
  • I don't understand your question. Please elaborate.
  • Sir I have used the above files for performing I2C interface,Is it OK.
  • Since you use it and don't see clock on clock pin, I suppose it is not OK.
  • Hello YK  Sir,

    Thanks for help I got the I2C module working on my board.

    Thanks and regards

    Ravindra Kant

  • You are welcome and it's good to know it works now.
  • Hello YK sir,

    I am getting confused as how the application layer know that light event has been occurred,as for the key event we call the API  registerkeys(task id ) to let the application know that key event has generated.

    In case of sensor what is the method to do that?'

    Thanks

  • I don't understand your question well. Can you elaborate?
  • Sir,
    Lets take an example for HA Sampleswitch ,on Z-stack CC2530,in the application layer zcl_samplesw.c,if any key is pressed then it gets notified through the key_change event ,now I am using sensor ,if any light event has occurred how to let the the application know that this event has occurred.

    Thanks
  • What kind of light event do you mean?
  • A flash Light event .
  • I mean how do you read this light event from CC2530?
  • I have used the light sensor interface it with CC2530 using I2C ,that how I am measuring the flash event.
  • I suppose you would set a periodic event to read light value from light sensor and if the value is larger than a threshold, you can trigger an event by osal_set_event.
  • Hello YK Sir,

    You have rightly said that for triggering an event one should use osal_set_event(task_id,event_flag),but I want if a light event occurs ,I should directly get the information in the Application layer not in the HAL layer.

    So for that can I pass the sampleapp task Id in the above API.

    Thanks!

  • Yes, you can call osal_set_event in application layer.
  • Hello Sir,
    I am using CC2530 ,Z-stack and referring HA SampleSwitch Application,when I run the program ,the interrupts on port 2 are working fine,but interrupts on Port 0 are not at all working.Is it the reason that port 0 pins are used elsewhere.


    Thanks and Regards
    Ravindra Kant
  • Yes, it could be. You can check P0 related registers to verify it.