Page 1 of 1

SPI_CR1_CPOL not working on STM32F427

Posted: Tue Aug 01, 2017 10:45 pm
by becafuel
Hello,

I have a board that is using a F427ZIT and I want to read data from the MCP3204 chip (this is an ADC). This chip is using mode (1,1).
So, I configure my config this way :

Code: Select all

uint16_t CR1 = SPI_CR1_BR_2 | SPI_CR1_SSI | SPI_CR1_MSTR | SPI_CR1_SPE | SPI_CR1_CPOL | SPI_CR1_CPHA;
  SPIConfig spi2_cfg =
  {
     NULL,
     GPIOE,                                          /*   port of CS on Socket #2   */
     GPIOE_CS2,                                      /*   pin of CS    */
     CR1,
    0
  };


Unfortunately, here is what I get :
Image

And here is what I should get (got this using NETMF) :
Image

Is there something I am doing wrong ? With the SPI_CR1_CPOL bit set, the clock line should be high, to me. Here it is low.
If I try Mode (0,0) then I get values back but those are wrong.


Regards,
________
Christophe

Re: SPI_CR1_CPOL not working on STM32F427

Posted: Thu Aug 03, 2017 2:18 pm
by becafuel
Nobody has any clue ? :?

Re: SPI_CR1_CPOL not working on STM32F427

Posted: Thu Aug 03, 2017 5:34 pm
by Giovanni
You are initializing a field of a presumably constant structure using a variable.

Giovanni

Re: SPI_CR1_CPOL not working on STM32F427

Posted: Thu Aug 03, 2017 6:23 pm
by becafuel
What is the point ? I do not understand what can go wrong with this ?

The same exact code does work on a F429 iDiscovery and if I set the value directly in the struct it does not work either on the F427 :

Code: Select all

SPIConfig spi5_cfg =
  {
     NULL,
     GPIOE,                                          /*   port of CS on Socket #2   */
     GPIOE_CS2,                                      /*   pin of CS    */
     SPI_CR1_SSI | SPI_CR1_MSTR | SPI_CR1_SPE | SPI_CR1_CPOL | SPI_CR1_CPHA,
    0
  };

Re: SPI_CR1_CPOL not working on STM32F427

Posted: Thu Aug 03, 2017 7:32 pm
by Giovanni
Hi,

Remove this:

SPI_CR1_SSI | SPI_CR1_MSTR | SPI_CR1_SPE

The driver handles those bits internally.

Giovanni

Re: SPI_CR1_CPOL not working on STM32F427

Posted: Fri Aug 04, 2017 10:47 am
by becafuel
Unfortunately, this does not change anything :(
The clock line is still held low.

Re: SPI_CR1_CPOL not working on STM32F427

Posted: Fri Aug 04, 2017 3:42 pm
by Giovanni
You should verify that:

1) Registers are setup as expected after spiStart().
2) That the behavior is not the expected one from the STM32 Reference Manual.

Giovanni