/* Sends data through a SPI peripheral. If the SPI is configured to use a fixed peripheral select, the npcs value is meaningless. Otherwise, it identifies the component which shall be addressed.  */
void SPI_Write(AT91S_SPI *spi, unsigned int npcs, unsigned short data)
/* Sends data through a SPI peripheral. If the SPI is configured to use a fixed peripheral select, the npcs value is meaningless. Otherwise, it identifies the component which shall be addressed.  */
void SPI_Write(AT91S_SPI *spi, unsigned int npcs, unsigned short data)
{
    while ((spi->SPI_SR & AT91C_SPI_TXEMPTY) == 0);
    spi->SPI_TDR = data | SPI_PCS(npcs);
    while ((spi->SPI_SR & AT91C_SPI_TDRE) == 0);
}