this is the program. this program build successfully but on simulation(SPI WINDOW SPI1_DR) it does not show any data please suggest....
#include "stm32f10x_lib.h" #define BufferSize 10 void RCC_Configuration(void); void GPIO_Configuration(void); void SPI_Configuration(void); ErrorStatus HSEStartUpStatus; u8 TxIdx = 0, RxIdx = 0; u8 SPI1_Buffer_Tx[BufferSize] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; u8 SPI1_Buffer_Rx[BufferSize]; int main(void) { RCC_Configuration(); GPIO_Configuration(); /* Just delay some time */ SPI_Configuration(); /* Enable SPI1 */ SPI_Cmd(SPI1, ENABLE); while(TxIdx < BufferSize) { SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx]); TxIdx++; } } 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_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) {} } /* Enable peripheral clocks ----------------------------------------------*/ /* GPIOA and SPI1 clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_DeInit(GPIOA); /* Configure SPI1 pins: SCK, MISO and MOSI -------------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); } void SPI_Configuration(void) { SPI_InitTypeDef SPI_InitStructure; SPI_I2S_DeInit(SPI1); /* Initialize the SPI_Direction member */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; /* initialize the SPI_Mode member */ SPI_InitStructure.SPI_Mode = SPI_Mode_Master; /* initialize the SPI_DataSize member */ SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; /* Initialize the SPI_CPOL member */ SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; /* Initialize the SPI_CPHA member */ SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; /* Initialize the SPI_NSS member */ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; /* Initialize the SPI_BaudRatePrescaler member */ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; /* Initialize the SPI_FirstBit member */ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; /* Initialize the SPI_CRCPolynomial member */ SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); }
thanks for your help, i am new to STM32 Controller so i just learned and started programming based on example programs.
what have to change in my program please help me.
You based your code on example programs?
Did the example programs work?
What is different between the example programs and your programs?
Have you spent time with the datasheet for the processor, so you know the answer to _why_ the different lines exists in the example programs? Or do you prefer to see the processor as black magic, and hope that copy/paste of random incantations will make the procesor perform its magic?
Mr. per i studied the reference manual of stm32f103 and also referred stdlibray firmware of stm32f10x series.
above program written on my own with reference to samples and other worked examples like GPIO toggle, led blinking, and even USART - TX,
please mention whats wrong with that code, what should add to work properly.