AnsweredAssumed Answered

SPI Peripheral data bit size on STM32F072

Question asked by Salieri on Jun 22, 2015
Latest reply on Sep 6, 2015 by karakiritsis.ilias

So I'm having a peculiar problem with the SPI on the STM32F072.

I'm trying to configure SPI1 and it seems to work, but with one cave-eat. I can't seem to configure the bit size (SCLK) down to 8b from 16b. I've been trying to do it through the CMSIS initialization structure but the changes aren't having any effect, so I've also tried it directly in the configuration registers. Still no luck.

The part where I tried configuring the registers manually:

     SPI1->CR2 &= ~(1<<11);
     SPI1->CR2 |= 0x700;
     SPI1->I2SCFGR &= ~(1<<10);
     SPI1->I2SCFGR &= ~(1<<11);

As you can see I've also thought about having the SPI configured in the I2S mode, but this doesn't seem to be the case.


The inserted picture is the oscillograph of the SPI Clock line (single transfer). No matter what I do, it clocks 16 bits.

The initialization routine is below:

     SPI_Cmd(SPI1, DISABLE);

     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set;

     SPI_Init(SPI1, &SPI_InitStructure);

     SPI1->CR2 &= ~(1<<11);          // 
     SPI1->CR2 |= 0x700;               // Set databyte size number to 0111

     SPI1->I2SCFGR &= ~(1<<10);     // Choose SPI mode
     SPI1->I2SCFGR &= ~(1<<11);     // Disable I2S Peripheral

     SPI_Cmd(SPI1, ENABLE);

I'd be very grateful for any help or ideas.