cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f10x - SPI not sending data

mbabu527
Associate II
Posted on February 24, 2012 at 10:16

please correct my code.

what is missing in that.....clarify...

#include ''stm32f10x_lib.h''
void RCC_Configuration(void);
void GPIO_Configuration(void);
void SPI_Configuration(void);
ErrorStatus HSEStartUpStatus;
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
SPI_Configuration();
SPI_Cmd(SPI1, ENABLE);
while(1)
{
SPI_I2S_SendData(SPI1, 0x01);
SPI_I2S_SendData(SPI1, 0x03);
}
}
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div2);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(0x00010000, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != 0x08) {}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void SPI_Configuration(void)
{
SPI_InitTypeDef SPI_InitStructure;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_Init(SPI1, &SPI_InitStructure);
}

#stm32f10x #spi #stm32
3 REPLIES 3
esiqueira
Associate II
Posted on February 24, 2012 at 11:45

Only one line is missing...

#include <stm32f10x_lib.h>

#include ''spi.h''

SPI_InitTypeDef  SPI_InitStructure;

/*----------------------------------------------------------------------------

 *        SPI Configuration

 *---------------------------------------------------------------------------*/

void SPI_Configuration(void)

{

  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(SPI1, &SPI_InitStructure);

 

  SPI_Cmd(SPI1, ENABLE);  

}

mbabu527
Associate II
Posted on February 25, 2012 at 10:50

still its not sending any data..

i added what you said but its not showing any data on simulation window.

Posted on February 25, 2012 at 15:31

Simulation? Does it work on real hardware?

You should wait for the peripheral to be ready before sending data too

    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..