This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

M0 SPI outputting 16bit not 8bit

I'm using the STM32F030K6T6 M0 processor and C++ in STM32CubeIDE and no matter what I try I'm outputting 16 bits instead of 8.

I created 2 projects; One HAL and the one shown partially below.  I run them in debug and the GPIOA and SPI setting are the same.  The HAL output is 8 bit format as it should be b ut the other outputs 16 bits per transaction as shown in the logic image below.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CSpi::CSpi() {
// Enable PA clock
RCC->AHBENR |= (1 << 17);
// Set PA5, PA6 and PA7 to Alt. Func.
GPIOA->MODER &= ~(0x3F << 10);
GPIOA->MODER |= (0x2A << 10);
GPIOA->AFR[0] &= ~(0xFFF << 20);
}
void CSpi::SpiInit()
{
RCC->APB2ENR |= (1 << 12); // enable SPI1 clock
SPI1->CR1 = 0x31C; // Master, clk/16, SSM/SSI
SPI1->CR2 = 0x01708; // 8 bit
SPI1->CR1 |= (1 << 6); // enable SPI1 module
}
bool CSpi::ConfigureChannel(uint8_t chan, GPIO_TypeDef* port, uint16_t pin)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and in my main routine I have;

Fullscreen
1
2
3
4
5
6
7
8
9
spi.SpiInit();
spi.ConfigureChannel(0, GPIOA, 4);
while(1)
{
spi.SetState(0, LOW);
spi.Write(0x31);
spi.SetState(0, HIGH);
delay(5);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

memx

Not sure what I'm doing wrong.

Any help appreciated.

0