How to receive data by using SPI communication ?
I use the STM32Lo538 disco board, and this board is connected to one sensor. Moreover, the protocol of this sensor is SPI. I faced difficulties receiving the data from the sensor. When I watched the waveform of this sensor, I noticed that the CS pin was driven from high to low, but data was not received by the master. Furthermore, I checked every possible condition, but still, data is not received by the master. However, I also tried the NSS pin, but this time I am only able to read one register and cannot read another register. What should I do?
CODE :-
void max30001_cs_pin_reset(){
HAL_GPIO_WritePin(BSP_MAX30001_NSS_PIN_GPIO_Port, BSP_MAX30001_NSS_PIN_Pin,
GPIO_PIN_RESET); // Set chip select low
// HAL_GPIO_WritePin(BSP_MAX30001_CS_PIN_GPIO_Port, BSP_MAX30001_CS_PIN_Pin,
// GPIO_PIN_RESET); // Set chip select low
}
void max30001_cs_pin_set() {
HAL_GPIO_WritePin(BSP_MAX30001_NSS_PIN_GPIO_Port, BSP_MAX30001_NSS_PIN_Pin,
GPIO_PIN_SET); // Set chip select high
// HAL_GPIO_WritePin(BSP_MAX30001_CS_PIN_GPIO_Port, BSP_MAX30001_CS_PIN_Pin,
// GPIO_PIN_SET); // Set chip select high
}
int32_t BSP_SPI1_Read(uint8_t *tx_buff, uint16_t tx_size, uint8_t *rx_buff,
uint16_t rx_size) {
HAL_StatusTypeDef ret = HAL_ERROR;
max30001_cs_pin_reset();
HAL_Delay(100);
ret = HAL_SPI_TransmitReceive(&hspi1, tx_buff, rx_buff, rx_size, 500);
if (ret == HAL_OK) {
max30001_cs_pin_set();
HAL_Delay(100);
return ret;
}
return ret;
}
int32_t BSP_SPI1_write(uint8_t *tx_buff, uint16_t tx_size, uint8_t *rx_buff,
uint16_t rx_size) {
HAL_StatusTypeDef ret = HAL_ERROR;
max30001_cs_pin_reset();
HAL_Delay(100);
ret = HAL_SPI_Transmit(&hspi1, tx_buff, tx_size, 100);
if (ret == HAL_OK) {
max30001_cs_pin_set();
HAL_Delay(100);
return ret;
}
return ret;
}