AnsweredAssumed Answered

SPI data register (SPI_DR) on STM32CubeMX ?

Question asked by H.Rick on Jan 18, 2016
Latest reply on Jan 20, 2016 by H.Rick
Guys,

Which API should I use for reading the value of SPI data register (SPI_DR) ?

How can I differentiate between data from SPI1 and SPI2 ?


I tried to port from AVR to STM32CubeMX...please have a look and correct me if I'm wrong :
STM32 :
/* Exchange a byte */
static
BYTE xchg_spi (     /* Returns received data */
    BYTE dat[1]     /* Data to be sent */
)
{
    while(HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
    HAL_SPI_Receive(&hspi2,dat,1,100);
    return dat[1];
}
 
AVR :
/* Exchange a byte */
static
BYTE xchg_spi (     /* Returns received data */
    BYTE dat        /* Data to be sent */
)
{
    SPDR = dat;
    loop_until_bit_is_set(SPSR, SPIF);
    return SPDR;
}

Thanks

Outcomes