Hello
I've had the same problem with the SPI on stm32f0 : the peripheral was configured in 8 bit mode but it would write 16 bits, the first 8 the actual data and the next 8 just 0.
I was not using the stm peripheral. library - just the platform header file.
In my case the problem was in the SPI typedef in stm32f0...h: the data type that was defined for the SPI data register is 16 bits: the compiler (gcc) will create that operation as a 16 bit write even if i casted all types to uint8
My fix was to alter the header file: create a union for the data register: two uint8 over a uint16 type or redefine the data register as uint8 DRH and DRL -> the write operation will explicitly be an 8 bits one and the compiler / peripheral will not get confused: SPI_DR typedef in the code below
in stm32f0xx.h
typedef union {
uint16_t DR;
struct{
unsigned char DR0;
unsigned char DR1;
};
}SPI_DR;
typedef struct
{
__IO uint16_t CR1; /*!< SPI Control register 1 (not used in I2S mode), Address offset: 0x00 */
uint16_t RESERVED0; /*!< Reserved, 0x02 */
__IO uint16_t CR2; /*!< SPI Control register 2, Address offset: 0x04 */
uint16_t RESERVED1; /*!< Reserved, 0x06 */
__IO uint16_t SR; /*!< SPI Status register, Address offset: 0x08 */
uint16_t RESERVED2; /*!< Reserved, 0x0A */
__IO SPI_DR DR; /*!< SPI data register, Address offset: 0x0C */
uint16_t RESERVED3; /*!< Reserved, 0x0E */
__IO uint16_t CRCPR; /*!< SPI CRC polynomial register (not used in I2S mode), Address offset: 0x10 */
uint16_t RESERVED4; /*!< Reserved, 0x12 */
__IO uint16_t RXCRCR; /*!< SPI Rx CRC register (not used in I2S mode), Address offset: 0x14 */
uint16_t RESERVED5; /*!< Reserved, 0x16 */
__IO uint16_t TXCRCR; /*!< SPI Tx CRC register (not used in I2S mode), Address offset: 0x18 */
uint16_t RESERVED6; /*!< Reserved, 0x1A */
__IO uint16_t I2SCFGR; /*!< SPI_I2S configuration register, Address offset: 0x1C */
uint16_t RESERVED7; /*!< Reserved, 0x1E */
__IO uint16_t I2SPR; /*!< SPI_I2S prescaler register, Address offset: 0x20 */
uint16_t RESERVED8; /*!< Reserved, 0x22 */
} SPI_TypeDef;