AnsweredAssumed Answered

Cannot activate 8 bit spi

Question asked by svinya.ryuzke on May 29, 2013
Latest reply on May 30, 2013 by s.b.003
Hi. I configured my STM32F3-Discovery SPI link to 8 bit data frame but no matter if I send 1 or 2 bytes through it, oscilloscope anyway registers 2 bytes being sent.

here is the code:
uint8_t readbyte(void){
    GPIO_WriteBit(GPIOD, GPIO_Pin_8, Bit_RESET);
    while((SPI1->SR & SPI_I2S_FLAG_TXE) == RESET);
    SPI2->DR = 0xDE;
    while((SPI1->SR & SPI_I2S_FLAG_RXNE) == RESET);
    GPIO_WriteBit(GPIOD, GPIO_Pin_8, Bit_SET);
    return SPI1->DR;
}
 
...
 
    SPI_InitTypeDef  SPI_InitStructure;
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_Init(&SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
 
...
 
while (1){
uint8_t u8 = readbyte();
Delay(1);
}

This happens when I send "0xDE" value:
http://i.imgur.com/jyfaRQc.png

This happens when I send "0xDEAD" value:
http://i.imgur.com/LY3VrfR.png

As you can see it sends 16 bits of data regardless of the SPI_DataSize setting.

I think this may be a bug of stdperiph lib? How do I fix this?

Outcomes