Skip to content

[NUCLEO_F072RB] Fix 8-bit data access issue with SPI slave #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,21 @@ static inline int ssp_writeable(spi_t *obj) {
static inline void ssp_write(spi_t *obj, int value) {
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));

if (obj->bits <= SPI_DATASIZE_8BIT) {
// force 8-bit access the data register due to SPI data buffer in this device
if (obj->bits == SPI_DATASIZE_8BIT) {
// Force 8-bit access to the data register
uint8_t *p_spi_dr = 0;
p_spi_dr = (uint8_t *) & (spi->DR);
*p_spi_dr = (uint8_t)value;
} else {
} else { // SPI_DATASIZE_16BIT
spi->DR = (uint16_t)value;
}
}

static inline int ssp_read(spi_t *obj) {
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));

if (obj->bits <= SPI_DATASIZE_8BIT) {
// force 8-bit access the data register due to SPI data buffer in this device
if (obj->bits == SPI_DATASIZE_8BIT) {
// Force 8-bit access to the data register
uint8_t *p_spi_dr = 0;
p_spi_dr = (uint8_t *) & (spi->DR);
return (int)(*p_spi_dr);
Expand Down Expand Up @@ -285,13 +283,27 @@ int spi_slave_receive(spi_t *obj) {
int spi_slave_read(spi_t *obj) {
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
return (int)spi->DR;
if (obj->bits == SPI_DATASIZE_8BIT) {
// Force 8-bit access to the data register
uint8_t *p_spi_dr = 0;
p_spi_dr = (uint8_t *) & (spi->DR);
return (int)(*p_spi_dr);
} else {
return (int)spi->DR;
}
}

void spi_slave_write(spi_t *obj, int value) {
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
spi->DR = (uint16_t)value;
if (obj->bits == SPI_DATASIZE_8BIT) {
// Force 8-bit access to the data register
uint8_t *p_spi_dr = 0;
p_spi_dr = (uint8_t *) & (spi->DR);
*p_spi_dr = (uint8_t)value;
} else { // SPI_DATASIZE_16BIT
spi->DR = (uint16_t)value;
}
}

int spi_busy(spi_t *obj) {
Expand Down