Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SPIBLOCKING_write(Spi *spid, const uint8_t *txbuf, uint16_t len)
- {
- SPI_TypeDef* spi = spid->spi;
- while (len--) {
- spi->DR = *txbuf++; // write a byte
- while (!(spi->SR & SPI_SR_RXNE));
- (void)spi->DR; // dummy read
- while (!(spi->SR & SPI_SR_TXE)); // make sure previous TX is done
- }
- }
- void SPIBLOCKING_read(Spi *spid, uint8_t *rxbuf, uint16_t len)
- {
- SPI_TypeDef* spi = spid->spi;
- while (len--) {
- spid->spi->DR = 0xFF; // write a dummy byte
- while(!(spi->SR & SPI_SR_RXNE)); // wait for data
- *rxbuf++ = spi->DR; // read it
- while(!(spi->SR & SPI_SR_TXE)); // make sure previous TX is done
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement