Sensirion / embedded-sps

Embedded i2c Driver for Sensirion Particulate Matter Sensors - Download the Zip Package from the Release Page
https://github.com/Sensirion/embedded-sps/releases
BSD 3-Clause "New" or "Revised" License
45 stars 15 forks source link

SPS Sensor Probing Failed! #58

Closed sfeaganUNO closed 3 weeks ago

sfeaganUNO commented 3 months ago

I implemented this software to connect to an SPS 30 PM sensor and it will not connect. I wrote my own drivers but only ever recieved back 0xff for bytes. I then implemented sps30-i2c-3.1.1 on a custom board using an STM32L071KZT6 MCU. The I2c bus has several sensors on it and they communicate well. I have three sps30 sensors and they all do the same. I modified the sensirion_hw_i2c_implementation for my i2c bus and should be correct. Its the same initialization as in my main.c, I am using STM32CubeIDE for this project. What are the chances i have three faulty sensors? I am not sure what i am doing wrong. I will paste my implementation below:

sensirion_hw_i2c_implementation:

include

include "sensirion_arch_config.h"

include "sensirion_i2c.h"

/**

/**

/**

/**

/**

/**

main.c:

/ USER CODE BEGIN Header / /**


/ Private includes ----------------------------------------------------------/ / USER CODE BEGIN Includes / //#include "ssd1306.c" //#include "fonts.c" / USER CODE END Includes /

/ Private typedef -----------------------------------------------------------/ / USER CODE BEGIN PTD /

define DELAY_PERIOD_MS (15*1000) // 15 seconds

/ USER CODE END PTD /

/ Private define ------------------------------------------------------------/ / USER CODE BEGIN PD /

/ USER CODE END PD /

/ Private macro -------------------------------------------------------------/ / USER CODE BEGIN PM /

/ USER CODE END PM /

/ Private variables ---------------------------------------------------------/ ADC_HandleTypeDef hadc;

CRC_HandleTypeDef hcrc;

I2C_HandleTypeDef hi2c1; I2C_HandleTypeDef hi2c3;

RTC_HandleTypeDef hrtc;

SPI_HandleTypeDef hspi1;

UART_HandleTypeDef huart1; UART_HandleTypeDef huart4;

/ USER CODE BEGIN PV / uint8_t data[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; char serial_msg[10]; void serial_string10(char str[10]); uint8_t ver_buf[3]; uint8_t id_buf[49]; uint8_t pim_buf[3]; uint8_t rdy; uint8_t num_err; char i2c_reading_buf[100]; //int8_t rslt = BME680_OK;

/ USER CODE END PV /

/ Private function prototypes -----------------------------------------------/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC_Init(void); static void MX_I2C1_Init(void); static void MX_SPI1_Init(void); static void MX_USART1_UART_Init(void); static void MX_USART4_UART_Init(void); static void MX_CRC_Init(void); static void MX_RTC_Init(void); static void MX_I2C3_Init(void); / USER CODE BEGIN PFP / uint8_t getPMversion(); int8_t bme680I2cRead(uint8_t dev_id, uint8_t reg_addr, uint8_t reg_data, uint16_t len); int8_t bme680I2cWrite(uint8_t dev_id, uint8_t reg_addr, uint8_t reg_data, uint16_t len); uint8_t getSFA30_id(); uint8_t getPIM_id();

define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

/ USER CODE END PFP /

/ Private user code ---------------------------------------------------------/ / USER CODE BEGIN 0 /

/ USER CODE END 0 /

/**

/ printf("Hello World\n\r"); HAL_Delay(1000); HAL_UART_Transmit(&huart1, "hello\n", 6, 1000); HAL_Delay(1000); rdy = sps30_wake(&pm_sensor); rdy = getPMversion(); rdy = getSFA30_id(); rdy = getPIM_id(); rdy = sps30_start_int(&pm_sensor); // HAL_Delay(5000); // HAL_Delay(5000); // HAL_Delay(5000); // HAL_Delay(5000); rdy = sps30_getData(&pm_sensor); rdy = sps30_getStatus(&pm_sensor); rdy = 1; // if (rdy == sps30_rdy(&pm_sensor)){ // rdy = sps30_stop(&pm_sensor); // rdy = sps30_getData(&pm_sensor); //}// end if /

/* USER CODE BEGIN 3 */

} / USER CODE END 3 / }

/**

/**

}

/**

}

/**

}

/**

}

/**

}

/**

}

/**

}

/**

}

/**

/ USER CODE BEGIN MX_GPIO_Init_2 / / USER CODE END MX_GPIO_Init_2 / }

/ USER CODE BEGIN 4 / void serial_string10(char temp[10]){

for(int i = 0; i < 10; i++){

    data[i] = temp[i];

}// end for

}//end serial strin10

uint8_t getPMversion(){ HAL_StatusTypeDef status;

//uint8_t pmAddrPtr[2]= {0xD1,  0x00};
status = HAL_I2C_Mem_Read(&hi2c1, 0x69 << 1, 0xD100, 2, ver_buf, 3, 1000);

if (status == HAL_OK){
        serial_string10("version: \n");
        HAL_UART_Transmit(&huart1, data, 10, 1000);
        HAL_Delay(1000);
        HAL_UART_Transmit(&huart1, ver_buf, 3, 1000);
        HAL_Delay(1000);
        return 1;
}// end if
else return 0;

}///end getpmversion

int8_t bme680I2cRead(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) { int8_t result;

if (HAL_I2C_Master_Transmit(&hi2c1, (dev_id << 1), &reg_addr, 1, HAL_MAX_DELAY) != HAL_OK) { result = -1; } else if (HAL_I2C_Master_Receive (&hi2c1, (dev_id << 1) | 0x01, reg_data, len, HAL_MAX_DELAY) != HAL_OK) { result = -1; } else { result = 0; }

return result; }/// end bme read

int8_t bme680I2cWrite(uint8_t dev_id, uint8_t reg_addr, uint8_t reg_data, uint16_t len) { int8_t result; int8_t buf;

// Allocate and load I2C transmit buffer buf = malloc(len + 1); buf[0] = reg_addr; memcpy(buf + 1, reg_data, len);

if (HAL_I2C_Master_Transmit(&hi2c1, (dev_id << 1), (uint8_t *) buf, len + 1, HAL_MAX_DELAY) != HAL_OK) { result = -1; } else { result = 0; }

free(buf); return result; }// end bme write

uint8_t getSFA30_id(){ HAL_StatusTypeDef status; id_buf[48] = '\n';

    //uint8_t pmAddrPtr[2]= {0xD1,  0x00};
    status = HAL_I2C_Mem_Read(&hi2c1, 0x5D << 1, 0xD060, 2, id_buf, 48, 1000);

    if (status == HAL_OK){
            serial_string10("version: \n");
            HAL_UART_Transmit(&huart1, data, 10, 1000);
            HAL_Delay(1000);
            HAL_UART_Transmit(&huart1, id_buf, 49, 1000);
            HAL_Delay(1000);
            return 1;
    }// end if
    return 0;

}//end getSFA30_id

uint8_t getPIM_id(){ HAL_StatusTypeDef status; pim_buf[2] = '\n';

        //uint8_t pmAddrPtr[2]= {0xD1,  0x00};
        status = HAL_I2C_Mem_Read(&hi2c1, 0x18 << 1, 0xFBFA, 2, pim_buf, 2, 1000);

        if (status == HAL_OK){
                serial_string10("version: \n");
                HAL_UART_Transmit(&huart1, data, 10, 1000);
                HAL_Delay(1000);
                HAL_UART_Transmit(&huart1, pim_buf, 2, 1000);
                HAL_Delay(1000);
                return 1;
        }// end if
        return 0;

}// end getPIM_id

/**

/ USER CODE END 4 /

/**

ifdef USE_FULL_ASSERT

/**

qfisch commented 3 months ago

Hej @sfeaganUNO , The likelyhood of you having 3 faulty SPS sensors are very small. What I would suggest is to narrow down your issue:

Quentin