/* Returns the most recent received data by the spi peripheral.  */
u32 SPI_ReceiveData(SPI_TypeDef *spi)
/* Returns the most recent received data by the spi peripheral.  */
u32 SPI_ReceiveData(SPI_TypeDef *spi)
{
    u32 temp;
    u8 templen;
    __asm volatile("cpsid i");
    temp = READ_REG(spi->RDR);
    templen = READ_REG(spi->ECR);
    if(templen  == 0)
        templen = 32;
    if (templen > 8)
        temp |= (u32)(READ_REG(spi->RDR) << 8);
    if (templen > 16)
        temp |= (u32)(READ_REG(spi->RDR) << 16);
    if (templen > 24)
        temp |= (u32)(READ_REG(spi->RDR) << 24);
    __asm volatile("cpsie i");
    return temp;
}