Hi
I am implementing a BSP581 alongside a ST time of flight sensor using an STM32G474 board, the time of flight has been completed using I2C and I am currently working on the BMP581 using SPI.
The problem I face is that the bsp5_init(&dev) call is returning -2, or BMP5_E_COM_FAIL, and I have struggled to make progress finding the source of this. As my debugging has progressed, the debug process has started to jump directly to Hardfault_Handler().
I am looking for advice on how to debug this, if any whilst I source a replacement sensor. Relevant sections of code are below:
In main()
dev.intf = BMP5_SPI_INTF;
dev.read = bmp5_spi_read;
dev.write = bmp5_spi_write;
dev.delay_us = bmp5_delay_us;
dev.intf_ptr = SPI2_CS_Pin; // e.g., pointer to SPI handle or chip select pin
int8_t rsltIN = bmp5_init(&dev); // initialise bmp5
printf("rsltIN: %d\n", rsltIN);
int8_t rsltPM = bmp5_set_power_mode(BMP5_POWERMODE_CONTINOUS, &dev); // set power mode to continuous
printf("rsltPM: %d\n", rsltPM);
My SPI read() and write() functions:
// SPI read function
int8_t bmp5_spi_read(uint8_t reg_addr, uint8_t data, uint32_t len, void intf_ptr) {
SPI_HandleTypeDef spi = (SPI_HandleTypeDef )intf_ptr;
int8_t readRslt = 0;
// Set MSB for SPI read
reg_addr |= 0x80;
// Pull CS low
HAL_GPIO_WritePin(BMP581_CS_GPIO_Port, BMP581_CS_Pin, GPIO_PIN_RESET);
// Send register address
if (HAL_SPI_Transmit(spi, ®_addr, 1, HAL_MAX_DELAY) != HAL_OK) {
readRslt = -1;
}
// Receive data
if (HAL_SPI_Receive(&spi, data, len, HAL_MAX_DELAY) != HAL_OK) {
readRslt = -2;
}
// Pull CS high
HAL_GPIO_WritePin(BMP581_CS_GPIO_Port, BMP581_CS_Pin, GPIO_PIN_SET);
return readRslt;
}
// SPI write function
int8_t bmp5_spi_write(uint8_t reg_addr, const uint8_t data, uint32_t len, void intf_ptr) {
SPI_HandleTypeDef spi = (SPI_HandleTypeDef )intf_ptr;
int8_t writeRslt = 0;
// Clear MSB for SPI write
reg_addr &= 0x7F;
// Pull CS low
HAL_GPIO_WritePin(BMP581_CS_GPIO_Port, BMP581_CS_Pin, GPIO_PIN_RESET);
// Send register address
if (HAL_SPI_Transmit(spi, ®_addr, 1, HAL_MAX_DELAY) != HAL_OK) {
writeRslt = -1;
}
// Send data
if (HAL_SPI_Transmit(spi, (uint8_t *)data, len, HAL_MAX_DELAY) != HAL_OK) {
writeRslt = -2;
}
// Pull CS high
HAL_GPIO_WritePin(BMP581_CS_GPIO_Port, BMP581_CS_Pin, GPIO_PIN_SET);
return writeRslt;
}
My board is wired as below and connections to the shuttle board are confirmed correct.
Please let me know if you need anything further.
Thanks