cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI error is not reported even with failed cases in STML4 device

anandhram1988
Associate II

 

HAL_SPI_Transmit(&hspi1, NULL, 0, 0);
uint32_t error = HAL_SPI_GetError(&hspi1);
HAL_SPI_StateTypeDef spiState = HAL_SPI_GetState(&hspi1);

 

above lines of code i expect error = error code
spiState must be error state , but i still gets  error  = 0, spistate = Ready 
anyone knows the reason?

10 REPLIES 10

@Andrew Neil wrote:

how would the hardware detect that there is no slave attached?

It can't


To expand on that, consider how an SPI transfer works:

  1. The Master asserts NSS - this is unaffected by whether a slave is connected or not
     
  2. The Master clocks out data on MOSI  - this is unaffected by whether a slave is connected or not
     
  3. Simultaneously, the Master samples data in MISO - there is no way to tell if the signal at MISO is actually coming from a slave, or is just open-circuit, or tied high, or tied low
     
  4. The Master releases NSS - this is unaffected by whether a slave is connected or not

So you can see that there is no way for the SPI hardware itself to know whether a slave is connected or not.

Similarly for a UART.

But I2C is different - because the I2C protocol requires certain actions from the Slave