AnsweredAssumed Answered

STM32F0: Trying to use SPI2 in 8-bit mode, but each transfer causes 16 clock cycles

Question asked by FarrellF on Mar 31, 2013
Latest reply on Apr 8, 2013 by waclawek.jan
I want to use SPI2 of an F0 in 8-bit mode. My stripped-down code is below. Looking at the SPI2_CLK line on a scope shows 16 cycles each time I write to SPI2->DR.

// reset and enable spi2
RCC->APB1RSTR |= RCC_APB1RSTR_SPI2RST;
RCC->APB1RSTR &= ~RCC_APB1RSTR_SPI2RST;
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;

// setup spi2 registers
SPI2->CR1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0;     // br = 111 = fpclk/256
SPI2->CR2 |= SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2;     // ds = 0111 = 8bit mode
SPI2->CR1 |= SPI_CR1_SSM | SPI_CR1_SSI;      // software slave management, software slave select
SPI2->CR1 |= SPI_CR1_MSTR;     // master
SPI2->CR1 |= SPI_CR1_SPE;     // spi enable

// wait for empty TX buffer
while((SPI2->SR & SPI_SR_TXE) == 0);

// send one byte of data ... but 16 bits get sent
SPI2->DR = 0x01;


Any ideas?

Thanks,
-Farrell

Outcomes