Question
STM32F3 discovery SPI communication
Posted on May 04, 2013 at 00:34
hello!
i'm an engineering student and i'm workingon a quad-copterproject. i have to use the stm32f3 discovery board to send gyro and accelerometer data throught spi to a rasberry pi board! the first step i did is trying to test the stm32 spi communication by doing a loopback test(MOSI to MISO) but i did not managed to do it! i did not found spi examples on stm32f3 but this is what i've coded :/// clock configuration
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
//// GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/// SPI
SPI_I2S_DeInit(SPI2);
SPIS.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPIS.SPI_DataSize = SPI_DataSize_8b;
SPIS.SPI_CPOL = SPI_CPOL_Low;
SPIS.SPI_CPHA = SPI_CPHA_1Edge;
SPIS.SPI_NSS = SPI_NSS_Soft;
SPIS.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPIS.SPI_FirstBit = SPI_FirstBit_MSB;
SPIS.SPI_CRCPolynomial = 7;
SPIS.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI2, &SPIS);
////sending data
a=0x08;
SPI_Cmd(SPI2, ENABLE);
SPI_SendData8(SPI2,a);
b=SPI_ReceiveData8(SPI2);
//testing the trasmission
if(b==0x08)
{
a++;
STM_EVAL_LEDOn(LED4);
} can you help plz?