Browse Source

Added alternative function for doing an SPI transfer.

pull/2/head
Fergus Noble 13 years ago
parent
commit
4809f7dacf
  1. 1
      include/libopencm3/stm32/spi.h
  2. 16
      lib/stm32_common/spi.c

1
include/libopencm3/stm32/spi.h

@ -290,6 +290,7 @@ void spi_disable(u32 spi);
void spi_write(u32 spi, u16 data);
void spi_send(u32 spi, u16 data);
u16 spi_read(u32 spi);
u16 spi_xfer(u32 spi, u16 data);
void spi_set_bidirectional_mode(u32 spi);
void spi_set_unidirectional_mode(u32 spi);
void spi_set_bidirectional_receive_only_mode(u32 spi);

16
lib/stm32_common/spi.c

@ -77,7 +77,7 @@ void spi_write(u32 spi, u16 data)
void spi_send(u32 spi, u16 data)
{
/* wait for transfer finished */
while (SPI_SR(spi) & SPI_SR_BSY );
while (!(SPI_SR(spi) & SPI_SR_TXE ));
/* Write data (8 or 16 bits, depending on DFF) into DR. */
SPI_DR(spi) = data;
@ -85,6 +85,20 @@ void spi_send(u32 spi, u16 data)
u16 spi_read(u32 spi)
{
/* wait for transfer finished */
while (!(SPI_SR(spi) & SPI_SR_RXNE ));
/* Read the data (8 or 16 bits, depending on DFF bit) from DR. */
return SPI_DR(spi);
}
u16 spi_xfer(u32 spi, u16 data)
{
spi_write(spi, data);
/* wait for transfer finished */
while (!(SPI_SR(spi) & SPI_SR_RXNE ));
/* Read the data (8 or 16 bits, depending on DFF bit) from DR. */
return SPI_DR(spi);
}

Loading…
Cancel
Save