cancel
Showing results for 
Search instead for 
Did you mean: 

I can't configure SPI1 on STM32F103C8

kashubadmitry
Associate II
Posted on November 25, 2016 at 07:04

Hi!

I have STM32F103C8 and want to configure SPI1!

I wrote the program

//spi1_mosi-pa7,spi1_miso-pa6,spi1_sck-pa5,spi1_nss-pa4

#include ''stm32f10x.h''

int main()

{

RCC->APB2ENR=RCC_APB2ENR_IOPAEN;

RCC->APB2ENR|=RCC_APB2ENR_AFIOEN;

RCC->APB2ENR|=RCC_APB2ENR_SPI1EN;

GPIOA->CRL|=GPIO_CRL_CNF7_1;//mosi

GPIOA->CRL|=GPIO_CRL_MODE7;

GPIOA->CRL|=GPIO_CRL_CNF6_1;//miso

  GPIOA->CRL&=~GPIO_CRL_MODE6;

GPIOA->CRL|=GPIO_CRL_CNF5_1;//sck

GPIOA->CRL|=GPIO_CRL_MODE5;

GPIOA->CRL|=GPIO_CRL_CNF4_1;//miso

  GPIOA->CRL&=~GPIO_CRL_MODE4;

SPI1->CR1=SPI_CR1_BR_0|SPI_CR1_BR_1|SPI_CR1_BR_2;

//SPI1->CR1=SPI_CR1_BIDIMODE;

//SPI1->CR1|=SPI_CR1_BIDIOE;

SPI1->CR1|=SPI_CR1_SSM;

SPI1->CR1|=SPI_CR1_SSI;

SPI1->CR1|=SPI_CR1_MSTR;

//SPI1->CR2=SPI_CR2_SSOE;

SPI1->CR1|=SPI_CR1_SPE;

while (1)

{

SPI1->DR=0x55;

while (!(SPI1->SR&SPI_SR_TXE));

}

There are no impulses on pins MOSI and SCK

What I did wrong?

Thank You!

1 REPLY 1
Posted on November 25, 2016 at 13:50

Read out and post the content of relevant GPIO and SPI registers.

JW