AnsweredAssumed Answered

SPI problem in stm32f10x

Question asked by mohamadi.parisa on Jan 6, 2017
Latest reply on Jan 10, 2017 by waclawek.jan

Hello

Here is my code

 

#include <stdio.h>
#include <string.h>
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_spi.h"

 

#define SPI_FLASH           SPI3
#define SPI_CLK             RCC_APB1Periph_SPI3
#define SPI_GPIO                GPIOC
#define SPI_GPIO_CLK        RCC_APB2Periph_GPIOC
#define SPI_PIN_SCK         GPIO_Pin_10
#define SPI_PIN_MISO        GPIO_Pin_11
#define SPI_PIN_MOSI        GPIO_Pin_12

 

void SPIConfig(void){
SPI_InitTypeDef  SPI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;

 

  /* Enable SPI and GPIO clocks */
  RCC_APB2PeriphClockCmd( SPI_GPIO_CLK , ENABLE);
  GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);

 

  /* Configure SPI pins: SCK, MISO and MOSI */
  GPIO_InitStructure.GPIO_Pin = SPI_PIN_SCK | SPI_PIN_MISO | SPI_PIN_MOSI;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(SPI_GPIO, &GPIO_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_Low;
  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_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI3, &SPI_InitStructure);

 

  /* Enable the SPI  */
  SPI_Cmd(SPI3, ENABLE);
}
    

 


void delay(){
    int i,j;
    for(i=0;i<10000;i++)
    for(j=0;j<250;j++);
}

 

int main(){        
SPIConfig();            

    while(1){            
    delay();delay();
    while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET);
    SPI_I2S_SendData(SPI3,0xff);    

    }

}

 

But unfortunately I can't see anything on CLK pin and  after I added "while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET);" line to my program it stops in this line.

 

what is my mistake?

 

Thanks in advamce

Outcomes