cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030F4 and SPI

vik1970va
Associate II
 
10 REPLIES 10

Try again with some content/description

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

After setting the bus IP in 1-line bidirectional data mode, the selected and Output enabled (transmit-only mode) DR register to which data is to be transmitted is in the "READ" state and it is impossible to write any data to it. I enclose part of the initialization code of the SPI bus. In this particular case, I connect the SPI screen and part of the pins intended for controlling the CS and RD. This code works on STM32F103C8B dv in several projects ...

vik1970va
Associate II

void SPI1_Init(void)

{

RCC->APB2ENR |= RCC_APB2ENR_SPI1EN ; //çàïóñê òàêòèðîâàíèÿ SPI1

RCC->AHBENR |= RCC_AHBENR_GPIOAEN ; //çàïóñê òàêòèðîâàíèÿ �?îðò À

// RCC->APB2ENR |= RCC_APB2ENR_AFIOEN ; //çàïóñê òàêòèðîâàíèÿ àëüòåðíàòèâíûõ ôóíêöèé

//èíèöèàëèçàöèÿ ïèíîâ äëÿ SPI1

  GPIO_StructInit(&ports);

  ports.GPIO_Mode = GPIO_Mode_AF;

  ports.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;

  ports.GPIO_Speed = GPIO_Speed_10MHz;

  GPIO_Init(GPIOA, &ports);

//èíèöèàëèçàöèÿ îñòàüíûõ ïèíîâ

  GPIO_StructInit(&ports);

  ports.GPIO_Mode = GPIO_Mode_OUT;

  ports.GPIO_Pin = LCD_CONT;

  ports.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(LCD_CTP, &ports);

  

 GPIO_StructInit(&ports);

 ports.GPIO_Mode = GPIO_Mode_OUT;

 ports.GPIO_Pin = GPIO_Pin_1;

 GPIO_Init(GPIOF, &ports);

//***********************************************************************************************

  SPI_StructInit(&spi);

  spi.SPI_Direction = SPI_Direction_1Line_Tx;

  spi.SPI_Mode = SPI_Mode_Master;

  spi.SPI_DataSize = SPI_DataSize_8b;

  spi.SPI_CPOL = SPI_CPOL_High;

  spi.SPI_CPHA = SPI_CPHA_2Edge;

  spi.SPI_NSS = SPI_NSS_Soft;

  spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;

  spi.SPI_FirstBit = SPI_FirstBit_MSB;

  spi.SPI_CRCPolynomial = 7;

  SPI_BiDirectionalLineConfig(SPI1, SPI_Direction_Tx);

  SPI_Init(SPI1, &spi);

  SPI_Cmd(SPI1, ENABLE); 

  SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);

   

//*********************************************************************************************** 

//òåñòîâàÿ ïðîâåðêà ïèíîâ CS RS RST

CS_HIGH;

RSET_HIGH;

RS_HIGH;

CS_LOW;

RS_LOW;

RSET_LOW

}

vik1970va
Associate II

Sorry for the bad English, the translator is not always able to lend specificity

vik1970va
Associate II

what's happening:

SPI_SendData8 (SPI1, 0X10); // SPI1-> DR = 0X10; //*(__IO uint8_t*)&SPI1 -> DR = (uint8_t)0X10;

This command should change the BSY: Busy flag = 1 and TXE: Transmit buffer empti = 0 but this does not happen. in the simulator everything works, but in the real board and with the debug not.

Read out the SPI control registers content and check.

JW

vik1970va
Associate II

0690X000006CO5rQAG.png0690X000006CO5mQAG.png Here, the truth is in the simulation, but with real performance it’s all the same.

RCC checked all set up as expected. I don’t even know where to look ... whether to change the microcontroller to the same one or to install the stm32f103�?b on which everything works ....

vik1970va
Associate II

Hello, spent the weekend to combat this problem.

In the standard setting of the SPI bus, the required signal is present at the MOSI, MISO, CLK outputs and the bus is working, but when trying to switch the bus to the “one line TX�? mode, the DR register is locked to write. MK is working and working fine, to control changed to the same and the result has not changed.

vik1970va
Associate II

I have already written 3 SPI bus configuration programs:

on registers, CMSIS, HAL and it did not help to solve my problem. Registr DR - READ(ONLY)