Hi.
I'm writing a piece of code which sends data via SPI from stm32l432kc, spi mode 2 (cpol = 1, phase = 0, 16 bits).
I don't use any library for that, just cmsis (bare metal).
SPI initialization:
AD_SPI->CR1 = 0;
constexpr uint32_t cr1 = (0b111 << SPI_CR1_BR_Pos) | SPI_CR1_MSTR_Msk | SPI_CR1_CPOL_Msk;
AD_SPI->CR1 = cr1;
AD_SPI->CR2 |= ~(SPI_CR2_DS_Msk) | (0b1111 << SPI_CR2_DS_Pos);
AD_SPI->CR1 = cr1 | SPI_CR1_SPE;
Writing to SPI:
while(! (spi_->SR & SPI_SR_TXE)) {}
spi_->DR = data;
while(! (spi_->SR & SPI_SR_RXNE)) {}
const uint16_t r = spi_->DR;
Attached is a scope screenshot of writing 0xC003 just to test, (two 1's at the beginning and at the end of 16 bits of data). Protocol decoder shows 0xE001, looks like extra 1 is added at the beginning, and the last bit is lost.
Tried to change different SPI settings, and SPI-writing code, it really doesn't change anything. I use the slowest SPI speed, clocks freq is about 15kHz, it doesn't look like signal integrity issue at all. Will try to test on another stm32 in a few days, but for now I'm stuck.
Any ideas what is happening there?
Screenshot attached, channels are SCK, MOSI, NSS.