2012-08-16 07:51 AM
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
http://www.analog.com/en/mems-sensors/mems-gyroscopes/adxrs450/products/product.html
.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 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3,ENABLE); //GPIO Takt f�r entsprechende Pins anschalten RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); 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); GPIO_PinAFConfig(GPIOC,GPIO_PinSource10,GPIO_AF_SPI3); //MOSI Configuration GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC,GPIO_PinSource12,GPIO_AF_SPI3); //MISO Configuration GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_SPI3); //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 GPIO_SetBits(GPIOA,GPIO_Pin_15); //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 SPI_Cmd(SPI3,ENABLE);}To test if CS is working i did this in the main function: while (1) { GPIO_SetBits(GPIOA,GPIO_Pin_15); delay100ms(); GPIO_ResetBits(GPIOA,GPIO_Pin_15); delay100ms(); }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,
Florian #stm32f4discovery-spi-cs-miso
2012-08-16 08:44 AM
Wouldn't MISO be driven by the SLAVE device? Observe it's behaviour when disconnected from the STM32
One-to-one wiring of MOSI Master, to MOSI Slave, MISO to MISO. The placement of CS would need to done with attention to where the first and last bits leave the STM32.