Cant communicate to SCD41 sensor on Click HVAC board

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
cmrelectrical
Posts: 19
Joined: 29 Dec 2020 12:06

Cant communicate to SCD41 sensor on Click HVAC board

#1 Post by cmrelectrical » 08 May 2023 11:15

Have a Click HVAC sensor mounted on breadboard controlled by a PIC16F887, I don't have a development board. Have reduced the code to the following where having started a periodic measurement, I go on to read just the C02 value without the CRC code. Once the routine is over, an LED should turn on to indicate the end of the routine but it gets hung up on the read from sensor " C02_read = I2C1_Rd (0u); " so the LED never turns on. I must be doing something wrong in addressing or reading the SCD41, has anyone any suggestions

#define SLAVE_ADDRESS 0x62
#define start_measurement_MSB 0x21
#define start_measurement_LSB 0xb1
#define read_c02_MSB 0xec
#define read_co2_LSB 0x05

unsigned int C02_read ;

void main(){
PORTB = 0;
TRISB = 0; // Configure PORTB as output
TRISC.F1= 0;
portc.F1= 0; // Turn ON LED on PORTC

I2C1_Init(100000); // initialize I2C communication
Delay_ms(1000);

I2C1_Start(); // issue I2C start signal
// send start next mesurment
//################################
I2C1_Wr(SLAVE_ADDRESS); // send byte via I2C (device address + W)
I2C1_Wr(start_measurement_MSB); // send start periodic measurement MSB
I2C1_Wr(start_measurement_LSB); // send start periodic measurement LSB
I2C1_Stop(); // issue I2C stop signal
//################################

Delay_ms(2000);

//################################
I2C1_Start(); // issue I2C start signal
I2C1_Wr(SLAVE_ADDRESS); // send byte via I2C (device address + W)
I2C1_Wr(read_c02_MSB); // send start periodic measurement MSB
I2C1_Wr(read_co2_LSB); // send start periodic measurement LSB
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(SLAVE_ADDRESS +1); // send byte (device address + R)
C02_read = I2C1_Rd (0u); // Read the data

// Add more reads for temp and RH, note each read is followed by a CRC code
I2C1_Stop(); // issue I2C stop signal
Delay_ms(500);
//################################

crap:
portc.F1= 1; // Turn ON LED on PORTC
goto crap;

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Cant communicate to SCD41 sensor on Click HVAC board

#2 Post by filip » 31 May 2023 07:39

Hi,

I apologize for the late reply, have you been able to sort out this issue ?

Regards,
Filip.

paulfjujo
Posts: 1551
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: Cant communicate to SCD41 sensor on Click HVAC board

#3 Post by paulfjujo » 01 Jun 2023 12:59

Hello,



did you try to read serial number,
so check if I2C link and sensor are ok...

3.9.2 get_serial_number
Description: Reading out the serial number can be used to identify the chip and to verify the presence of the sensor.
The get serial number command returns 3 words, and every word is followed by an 8-bit CRC checksum. Together, the 3 words
constitute a unique serial number with a length of 48 bits (big endian format).
Table 24: get_serial_number I2C sequence description
cde: 0x3682
response : 9 bytes serial number
Example: serial number is 273’325’796’834’238

Post Reply

Return to “mikroC PRO for PIC General”