cancel
Showing results for 
Search instead for 
Did you mean: 

SPI need help

timothy
Associate II
Posted on July 16, 2013 at 05:15

So ive been trying to get the SPI interface working. Here's what i have so far.

void SPI_Setup(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_I2S_DeInit(SPI1);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; 
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 0x1021;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_CalculateCRC(SPI1, ENABLE);
SPI_Cmd(SPI1, ENABLE);
}
void SPI_conf(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 ,ENABLE);
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //PA7-MOSI
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //PA7-MOSI
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //PA5-SCK
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //PA4-NSS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
}

I dont know what else to do. so any help is welcome. Next is how im Sending data, i hope

SPI_I2S_SendData(SPI1, 0x1);

SPI_I2S_SendData(SPI1, 0x1);

#stm32-spi-f103
4 REPLIES 4
Posted on July 16, 2013 at 09:36

You need to set the AF of relevant pins.

Follow the examples.

JW

septijo
Associate II
Posted on August 08, 2013 at 20:03

Dear waclawek.jan,

''follow the example'' .. where is the example ? can you provide the link .. please ?

i really need a woking example / step by step tutorial for STM32F0 SPI Slave, been searching for days with no luck..

thanks before

Posted on August 08, 2013 at 20:51

\STM32F0xx_StdPeriph_Lib_V1.0.0\Project\STM32F0xx_StdPeriph_Examples\SPI\SPI_TwoBoards\DataExchangeInterrupt\main.c

 Has a Master and Slave build configuration?

Don't know where the library code is? Try here

http://www.st.com/web/en/catalog/tools/PF257884

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
septijo
Associate II
Posted on August 09, 2013 at 16:00

@clive1 : Thanks a lot !!