2013-07-15 08:15 PM
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
2013-07-16 12:36 AM
You need to set the AF of relevant pins.
Follow the examples. JW2013-08-08 11:03 AM
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 before2013-08-08 11:51 AM
\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 herehttp://www.st.com/web/en/catalog/tools/PF257884
2013-08-09 07:00 AM
@clive1 : Thanks a lot !!