Announcements
Community Announcement : Welcome to the NEW Cypress Developer Community.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4

DaBr_1233126
Contributor

Has anyone had any success using the SI Labs Temperature and Humidity Sensors?

   

I am unable to read the sensor reliably.  There is a CRC check function that is validating the 1st, 3rd and 5th reads when I have a CyDelay(1), but nothing else.  Without the delay (as shown below) the first read is valid, but no others.  I have tried changing the delays up to 1000 with no difference.

   

<code>
float SI7013_readHumidity(void)
{
//Request a humidity reading
    I2C_1_I2CMasterSendStart(SI7013_ADDRESS, I2C_WRITE);
    I2C_1_I2CMasterWriteByte(MEASURE_RH_NOHOLD);             // Register to write at.
    I2C_1_I2CMasterSendStop();
//Hang out while measurement is taken.
CyDelay(130);
    
uint8 msb, lsb, checksum;
    I2C_1_I2CMasterSendStart(SI7013_ADDRESS, I2C_READ);
    
msb      = I2C_1_I2CMasterReadByte(I2C_1_I2C_ACK_DATA);
//CyDelay(1);
lsb      = I2C_1_I2CMasterReadByte(I2C_1_I2C_ACK_DATA);
//CyDelay(1);
checksum = I2C_1_I2CMasterReadByte(I2C_1_I2C_ACK_DATA);
//CyDelay(5);
    I2C_1_I2CMasterSendStop();
//CyDelay(5);
uint16 rawHumidity = ((unsigned int) msb << 😎 | (unsigned int) lsb;
if(SI7013_check_crc(rawHumidity, checksum) != 0) return(999); //Error out
//sensorStatus = rawHumidity & 0x0003; //Grab only the right two bits
rawHumidity &= 0xFFFC; //Zero out the status bits but keep them in place
//Given the raw humidity data, calculate the actual relative humidity
float tempRH = rawHumidity / (float)65536; //2^16 = 65536
float rh = -6 + (125 * tempRH); //From page 14
return(rh);
}
</code>

   

I am hoping that I am just doing something stupid here.

   

Parts are on a custom PCB.  I2C traces are VERY close to matched.  I am using the original library on an arduino connected to the sensor via a cable and it works fine.  So it isn't the sensor.

   

I have attached the Project.  I am using Creator 4.1 Update 1.  

0 Likes
1 Solution
Bob_Marlowe
Expert II

Try the attached corrected project. More conform to I2C handling

   

 

   

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Expert II

Try the attached corrected project. More conform to I2C handling

   

 

   

Bob

View solution in original post

0 Likes
DaBr_1233126
Contributor

Thanks Bob!  Your code works very well.

   

I also got the following code to work:

   


    I2C_1_I2CMasterSendStart(SI7013_ADDRESS, I2C_WRITE);
    I2C_1_I2CMasterWriteByte(MEASURE_RH_NOHOLD);             // Register to write at.
    I2C_1_I2CMasterSendStop();
    //Hang out while measurement is taken.
    CyDelay(60);
    
    uint8 msb, lsb, checksum;
    uint8  buffer[3];
    (void) I2C_1_I2CMasterReadBuf(SI7013_ADDRESS, buffer, 3, I2C_1_I2C_MODE_COMPLETE_XFER);
    while (0u == (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT))  {    }
    msb      = buffer[0];
    lsb      = buffer[1];
    checksum = buffer[2];

Not as eligant as yours, but it did work!

   

Thanks again!

0 Likes
DaBr_1233126
Contributor

I am attaching the working project for anyone else who is interested.  Code should work for the Si7006, Si7013, Si7020 and Si7021 sensors.