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.

CC2530: Temperature&Humidity Sensor DHT22 with CC2530

Part Number: CC2530

I want to use DHT22 Temperature&Humidity Sensor with CC2530 EM but I want a Library for this sensor 

  • Hi Mohammed,

    For your sensor, you will need develop a library/driver on your own.
    This will involve looking through the datasheet. For more direction look through an example library for an Arduino is available here: learn.adafruit.com/.../downloads
    From there it is a matter of looking through that library to see how the sensor is setup, read from and written to.

    -Sy Su
  • There’s no existing driver or library. You have to read data sheet and implement it by yourself.

  • I write this Code for DHT22 With CC2530 but it doesn't work there is no response from the sensor

    where is the problem ? Please

    4265.main.c
    /******************** (C) COPYRIGHT 2012 waveshare ********************
    * File Name          : main.c
    * Author             : waveshare.xuwenjie
    * Version            : V1.0.0
    * Date               : 29/10/2012
    * Description        : 
    ************************************************************************/
    
    #include <ioCC2530.h>
    #include <string.h>
    #include "LCD22.h"
    #include "Touchpanel.h"
    
    #define uint unsigned int
    #define uchar unsigned char
    #define uint16 unsigned short
    
    #define DATA_PIN P1_2 
    
    unsigned Temp, RH, Sum ;
    
    uchar Check , T_byte1 , T_byte2 , RH_byte1 , RH_byte2 ;
    
    
    
    void delay_us (uint16 timeout) 
    {
        while (timeout--)
        {
            asm("NOP");
            asm("NOP");
            asm("NOP");
        }
    }
    
    void StartSignal()
    {
      P1DIR |=  (1<<2);              // Configure connection pin as output
      DATA_PIN = 0;                        // Connection pin output low
      Delay_ms(30);
      DATA_PIN = 1;                        // Connection pin output high
      delay_us(30);
      P1DIR &=  ~(1<<2);              // Configure connection pin as input
     }
    
    void CheckResponse()
     {
      Check = 0;
      delay_us(40);
      if (DATA_PIN == 0)
       {
          delay_us(80);
          if (DATA_PIN == 1)   
             Check = 1;   
             delay_us(40);
       }
     }
    
    
    char ReadData()
    {
     char i, j;
     for(j = 0; j < 8; j++)
      {
         while(!DATA_PIN); //Wait until PORTD.F0 goes HIGH
         delay_us(30);
         if(DATA_PIN == 0)
           i&= ~(1<<(7 - j));  //Clear bit (7-b)
         else 
          {
             i|= (1 << (7 - j));  //Set bit (7-b)
             while(DATA_PIN);     //Wait until PORTD.F0 goes LOW
          }  
      }
     return i;
    }
    
    
    
    
    /*******************************************************************************
    * Function Name  : SystemInit
    * Description    : Initialize the system
    * Input          : None
    * Output         : None
    * Return         : None
    * Attention		 : None
    *******************************************************************************/
    
    void SystemInit(void)
    {
    	CLKCONCMD &= ~0x40;               //*Sets the system clock source for 32 MHZ crystal oscillator
    	while(CLKCONSTA & 0x40);          //* Wait for Oscillator to be ready    
    	CLKCONCMD &= ~0x47;               //*Sets the system master clock frequency for 32 MHZ
    }
    
    
    void Init_UART(void)
    {
      PERCFG = 0x00; //Peripheral-control register
      P0SEL = 0x0c; //P0_2=RX,P0_3=TX for peripheral control
      P2DIR &= ~0XC0; //set periorty to USRT0
      U0CSR |= 0x80; //control and status reg
    
      //Bit7 select mode :0 spi mode , 1 UART mode
      
      U0GCR |= 7; //U0GCR[4:0] & U0BAUD defines baud-rate
      U0BAUD |= 59; //baud-rate is 115200
      UTX0IF = 0; //(0: Interrupt not pending , 1: Interrupt pending)
      URX0IF = 0;
    }
    
    
    void dsply_num( unsigned int Xpos , unsigned int Ypos , unsigned int Color , uint16 a )
    {
      uint16 b=0;
      uint16 c=0;
      uint16 d=0;
      uint16 e=0;
      uint16 f=0;
      uint16 g=0;
    
      d=a/1000;
      e=a%1000;
      c=e/100;
      b=e%100;
      f=b/10;
      g=b%10;
    
      PutChar( Xpos , Ypos , d+48 , Color , 15 );
      PutChar( Xpos + 10 , Ypos , c+48 , Color , 15 );
      PutChar( Xpos + 20 , Ypos , f+48 , Color , 15 );
      PutChar( Xpos + 30 , Ypos , g+48 , Color , 15 );
    
      U0DBUF=d+48;
      while(!UTX0IF);
      UTX0IF = 0;
      U0DBUF=c+48;
      while(!UTX0IF);
      UTX0IF = 0;
      U0DBUF=f+48;
      while(!UTX0IF);
      UTX0IF = 0;
      U0DBUF=g+48;
      while(!UTX0IF);
      UTX0IF = 0 ;
      U0DBUF= '/' +48;
    }
    
    
    
    
    /*******************************************************************************
    * Function Name  : main
    * Description    : Main program
    * Input          : None
    * Output         : None
    * Return         : None
    * Attention		 : None
    *******************************************************************************/
    //extern U8 WenDu,ShiDu;//�����¶ȴ�ű���
    
    void main(void)
    {	
      
     
       SystemInit(); 
       Init_UART();
       
       LCD_Initializtion();
       Disp_Touchpanel(); 
       
       StartSignal();
       CheckResponse();
       
       while(1)
       {
         
         if(Check == 1)
          {
             RH_byte1 = ReadData();
             RH_byte2 = ReadData();
             T_byte1 = ReadData();
             T_byte2 = ReadData();
             Sum = ReadData();
      
             if(Sum == ((RH_byte1+RH_byte2+T_byte1+T_byte2) & 0XFF))
               {
                  Temp = T_byte1;
                  Temp = (Temp << 8) | T_byte2;
                  
                  RH = RH_byte1;
                  RH = (RH << 8) | RH_byte2;
                  
                  GUI_Text( 50 , 50 ,  "Temp:   . C" , White , 15 );
                  GUI_Text( 46 , 100 , "Humidity:   . %" , Red , 15 );
                 
                  if (Temp > 0X8000)
                   {
                      GUI_Text( 55 , 50 ,  "-" , White , 15 );
                      Temp = Temp & 0X7FFF; 
                   }
                 PutChar( 56 , 50 , 48 + ((Temp / 100) % 10) , White , 15 ); 
                 PutChar( 57 , 50 , 48 + ((Temp / 10) % 10) , White , 15 ); 
                 PutChar( 59 , 50 , 48 + (Temp % 10) , White , 15 ); 
                
                 PutChar( 56 , 100 , 48 + ((RH / 100) % 10) , White , 15 ); 
                 PutChar( 57 , 100 , 48 + ((RH / 10) % 10) , White , 15 ); 
                 PutChar( 59 , 100 , 48 + (RH % 10) , White , 15 ); 
                 
                
               }
              else
               {
                  
                  GUI_Text( 46 , 50 , "***** Check sum error*****" , Red , 15 );
                  GUI_Text( 46 , 100, "****** Check sum error****" , Red , 15 );
                  
               }
           }
          else 
           {
               GUI_Text( 46 , 50 , "***********No response" , Red , 15 );
               GUI_Text( 46 , 100, "from the sensor*******" , Red , 15 );
               
           }
             Delay_ms(1000);
        }
        
       
       
    }
    
    

  • Check P1SEL to see if bit 2 (I suppose you use P1.2 as GPIO to read SHT22) is set to 0.

  • This is not the problem you have modified but nothing has happened

  • Couldn’t understand your descriptions. Is your issue fixed?
  • I make a check  P1SEL to see if bit 2   is set to 0

    but there is no change and there is no response from the sensor