SPI_CR1_CPOL not working on STM32F427

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
becafuel
Posts: 15
Joined: Sun Feb 19, 2017 1:45 pm

SPI_CR1_CPOL not working on STM32F427

Post 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
becafuel
Posts: 15
Joined: Sun Feb 19, 2017 1:45 pm

Re: SPI_CR1_CPOL not working on STM32F427

Post by becafuel »

Nobody has any clue ? :?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI_CR1_CPOL not working on STM32F427

Post by Giovanni »

You are initializing a field of a presumably constant structure using a variable.

Giovanni
becafuel
Posts: 15
Joined: Sun Feb 19, 2017 1:45 pm

Re: SPI_CR1_CPOL not working on STM32F427

Post 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
  };
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI_CR1_CPOL not working on STM32F427

Post by Giovanni »

Hi,

Remove this:

SPI_CR1_SSI | SPI_CR1_MSTR | SPI_CR1_SPE

The driver handles those bits internally.

Giovanni
becafuel
Posts: 15
Joined: Sun Feb 19, 2017 1:45 pm

Re: SPI_CR1_CPOL not working on STM32F427

Post by becafuel »

Unfortunately, this does not change anything :(
The clock line is still held low.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI_CR1_CPOL not working on STM32F427

Post 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
Post Reply