Skip to content
Snippets Groups Projects
Commit 90d5c5e9 authored by Luca Erbetta's avatar Luca Erbetta :rocket:
Browse files

[BusTemplate] Wait for TXE before doing something on the bus

parent c3822be1
No related branches found
No related tags found
No related merge requests found
......@@ -110,6 +110,9 @@ private:
inline void _write(uint8_t byte) const
{
// Wait until the peripheral is ready to transmit
while ((getSPIAddr(N)->SR & SPI_SR_TXE) == 0)
;
getSPIAddr(N)->DR = byte;
while ((getSPIAddr(N)->SR & SPI_SR_RXNE) == 0)
;
......@@ -127,6 +130,9 @@ private:
inline uint8_t _read() const
{
// Wait until the peripheral is ready to transmit
while ((getSPIAddr(N)->SR & SPI_SR_TXE) == 0)
;
getSPIAddr(N)->DR = 0;
while ((getSPIAddr(N)->SR & SPI_SR_RXNE) == 0)
;
......@@ -157,6 +163,9 @@ private:
*/
inline uint8_t _transfer(uint8_t* byte)
{
// Wait until the peripheral is ready to transmit
while ((getSPIAddr(N)->SR & SPI_SR_TXE) == 0)
;
getSPIAddr(N)->DR = *byte;
while ((getSPIAddr(N)->SR & SPI_SR_RXNE) == 0)
;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment