RRH62000 Sleep/wakeup, CRC

Hello,

I'm connecting the sensor through I2C - I can read correct data frame if it's awake all the time.

What sequence is required in this case? This code, for example, does not work - received frame has invalid data (even if I keep reading them for some time):

#define RRH62000_I2C_SDA D1
#define RRH62000_I2C_SCL D2
#define RRH62000_I2C_ADDR 0x69
#define RRH62000_I2C_FRAME_BYTES 37

void setup()
{
  ...
  Wire.begin(RRH62000_I2C_SDA, RRH62000_I2C_SCL, RRH62000_I2C_ADDR);
  ...
}

void loop()
{
  Wire.beginTransmission(RRH62000_I2C_ADDR);
  Wire.write(0x50); Wire.write(0x80); // WAKE-UP
  Wire.endTransmission();
  
  delay(1000);  // wait some time

  unsigned char index = 0;
  Wire.requestFrom(RRH62000_I2C_ADDR, RRH62000_I2C_FRAME_BYTES);
  while(Wire.available())
  {
    RRH62000_Frame[index] = Wire.read();
    index++;
  }
  
  RRH62000_Frame_Temperature = ((RRH62000_Frame[24] << 8) | RRH62000_Frame[25]) * 0.01;
  ...
  
  Wire.beginTransmission(RRH62000_I2C_ADDR);
  Wire.write(0x50); Wire.write(0);  // SLEEP
  Wire.endTransmission();
  
  delay(1000);  // wait some time
}

The result:

RRH62000 Frame: 0:FF 1:FF 2:A 3:3 4:E8 5:3 6:E8 7:FF 8:FF 9:4E 10:C0 11:A 12:19 13:17 14:A6 15:A6 16:A6 17:A6 18:A6 19:A6 20:A6 21:A6 22:A6 23:A6 24:A6 25:A6 26:A6 27:A6 28:A6 29:A6 30:A6 31:A6 32:A6 33:A6 34:A6 35:A6 36:A6 

Without sleep/wake-up I get the following:


RRH62000 Frame: 0:0 1:0 2:0 3:A6 4:0 5:39 6:0 7:E 8:0 9:1 10:0 11:0 12:0 13:1C 14:0 15:75 16:0 17:BA 18:0 19:3C 20:0 21:3F 22:0 23:3F 24:9 25:F1 26:19 27:A1 28:0 29:2 30:1 31:90 32:0 33:64 34:0 35:0 36:45 
Temperature:25.5C
Humidity:65.6%
PM1:2.8ug/m3
PM2.5:11.7ug/m3
PM10:18.6ug/m3
TVOC:20ug/m3
eCO2:400ppm



Next question, do you have a C code for generating the CRC checksum?

Thank you very much!

Parents
  • Hello,

    Thanks for reaching out Renesas Engineering Community.

    Unfortunattely there is no sample code published yet for I2C communication for RRH62000 sensor.

    However we provide a middleware which you can maybe take as reference for our RA MCU  Family and FSP 5.6.0.

    I will share with you a project to see the code and the basic operation for I2C communication with the specific sensor.

    Regarding calculating the checksum there is also a function implemented in the code I will share with you the 

    rm_rrh62000_crc_execute.

    The code for calculating the checksum should look like this:

    void rrh62000_crc_execute (void)
    {
        uint8_t crc;
        uint8_t i;
        uint8_t j;
        
        /*Set initial value*/
        crc = 0xFF;
        for ( i =0; i<36; i++)
        {
            crc = raw_data[i];
            for(j=0;j<8;j++)
            {
                if(0x80 == (crc &0x80))
                {
                    /* If MSB is 1, calculate XOR with the polynomial. */
                    crc = (uint8_t) (crc <<1) ^ 0x31;
                
                }
                else
                {
                    crc << =1;
            
                }
            }
                
        }
            /*Final XOR*/
            crc ^ = 0x00;
            
        if (crc == raw_data[36])
        {
            printf("Correct crc-Valid Data \n");
        }
            
        else
        {
            printf("Invalid data \n");
        }
            
    }

    RA4M2_RRH.zip

    Hope it helps.

    BR,

    IK

  • Hello,

    thank you for the answer and the attached zip file.

    I can confirm that CRC calculation from the zip works (but not the one pasted above), e.g.

      #define RM_RRH62000_CALC_CRC_INITIAL_VALUE        (0xFF)
      #define RM_RRH62000_CALC_CRC_DATA_LENGTH          (36)
      #define RM_RRH62000_CALC_CRC_8BITS_LENGTH         (8)
      #define RM_RRH62000_CALC_CRC_0X80                 (0x80)
      #define RM_RRH62000_CALC_CRC_MASK_MSB             (0x80)
      #define RM_RRH62000_CALC_CRC_POLYNOMIAL           (0x31)
      #define RM_RRH62000_CALC_CRC_FINAL_XOR            (0x00)
    
      uint8_t         crc;
      const uint8_t * p_input_data;
      uint8_t         i;
      uint8_t         j;
    
      /* Set pointer to input data */
      p_input_data = &RRH62000_Frame[0];
    
      /* Set initial value */
      crc = RM_RRH62000_CALC_CRC_INITIAL_VALUE;
    
      /* Execute CRC */
      for (i = 0; i < RM_RRH62000_CALC_CRC_DATA_LENGTH; i++)
      {
        /* Calculate XOR with input value */
        crc ^= *p_input_data;
        for (j = 0; j < RM_RRH62000_CALC_CRC_8BITS_LENGTH; j++)
        {
          if (RM_RRH62000_CALC_CRC_0X80 == (crc & RM_RRH62000_CALC_CRC_MASK_MSB))
          {
            /* If MSB is 1, calculate XOR with the polynomial. */
            crc = (uint8_t) (crc << 1) ^ RM_RRH62000_CALC_CRC_POLYNOMIAL;
          }
          else
          {
            crc <<= 1;
          }
        }
        p_input_data++;
      }
    
      /* Final XOR */
      crc ^= RM_RRH62000_CALC_CRC_FINAL_XOR;
    
      Serial.print("\nCalculated CRC: ");
      Serial.print(crc, HEX);
      
      Serial.print("\nReported CRC: ");
      Serial.print(RRH62000_Frame[36], HEX);

    Unfortunately there's no sleep/wakeup sequence in the zip.

    I can switch the sensor Vcc on/off, but it would be really great if sleep/wakeup functionality would be documented...

  • Hello,

    Yes sorry for this I have updated the checksum function I provided you initially since some steps were missing.

    Now the one provided above should work. 

    Is your sensor still getting invalid readings when trying the sequence as in the middleware we provide for our RA MCUs?

    Best Regards,

    IK

  • Hello,

    the CRC calculation sequence from provided middleware works fine.

    The question is only sleep/wake-up functionality, e.g. to periodically read the sensor results in battery-powered application.

  • Hello,

    As far I can understand your requirement is to be able to put the sensor to sleep and wake-up whenever you want to take a measurement.

    Yes unfortunately the code from the middleware in the project I provided you does not have this functionality.

    Since in the middleware sleep command is not supported and has not been implemented yet.

    It will be added in the next releases.

    However let me check this also internally to see if there is something you should specifically do and follow after waking-up the sensor. Since in the datasheet of the sensor nothing is mentioned about it.

    Something else I would like to point out is that in your code you attached before requesting to read this 37 bytes you do not send the read command as mentioned in the commands of the datasheet.

    So the sequence should be like this:

    1. Wake up the sensor by sending through I2C bus 2 bytes (0x50,0x80)

    2.Wait 

    3. Send command 0x00.Read command

    4. Request to read 37 bytes .

    5. Go to sleep by sending through I2C bus 2 bytes (0x50,0x00).

    Best Regards,

    IK

  • Hello,

    sorry for the delay.

    Send command 0x00.Read command

    This solves the problem, thank you very much!

    Regards,

    Damjan

Reply Children
No Data