AnsweredAssumed Answered

SPI Beginner-Question (MISO follows CS????)

Question asked by Neiro on Aug 16, 2012
Latest reply on Aug 16, 2012 by Clive One
Should be okay now, thanks for the attention!


Dear STM32 experts,

i'm doing my first SPI bus and i'm coding STM32 for a week now so please don't be too hard :D
I'm trying to interface a ADXRS450.
So this is my SPI initialization code:

---The questions are below the code---

void spi3con(void) {
  //Pin Konfiguration: PA15: CS; PC10: SPI3_SCK; PC11: SPI3_MISO; PC12: SPI3_MOSI;
  //SPI1 hängt an APB1
  //Clock für SPI3 anschalten
  //GPIO Takt für entsprechende Pins anschalten
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  //Clock-Pin Configuration
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  //MOSI Configuration
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  //MISO Configuration
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  //CS Configuration
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  //SPI1 Configuration
  //Unselect CHIP --> CS high Pegel
  //Full Duplex
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  //STM32F4 ist Master
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 
  //16 bit Modus
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
  //Clock level zero in idle; clock polarity = 0
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  //CPHA = 0
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  //PA15 soll als normaler Pin zu verwenden sein
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  //APB1 = 42 MHz; SCLK max 8,08 MHz; Prescaler --> 8 --> SCLK = 5,25 MHz
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
  //MSB first (Seite 19 im Datenblatt ADXRS450)
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  //???? Kein Crc??
  SPI_InitStructure.SPI_CRCPolynomial = 0;
  //SPI3 Einstellungen schreiben
  SPI_Init(SPI3, &SPI_InitStructure);
  //SPI3 einschalten

To test if CS is working i did this in the main function:

 while (1)

Now i see on my logic analyzer that MISO is the same as CS. But CS is like expected. 
Is this normal or where is my mistake?
There is no shortcircuit in it, it tried it, if i initalize all pins as GPIO everything is okay.
And my second question: How can i disable the crc thing for spi? I wrote a zero in it, is that right?

Thank you for you help!!
Best regards,