cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] [STM32H503] SPI1 does not send anything

smalcom1
Associate

Good day, everyone.

I'm trying to launch SPI1 under Arduino IDE. The transmission didn't work and I switched to direct control of the registers. The code used is below:

 

 

#include <Arduino.h>
#include <SPI.h>


void setup()
{
	SPI.begin();
	Serial1.begin(115200);
}

void loop()
{
	Serial1.print("loop begin: ");
	Serial1.println(millis());

	SPI1->CR1 &= ~SPI_CR1_SPE;
	SPI1->CR2 = 0;
	SPI1->CR1 |= SPI_CR1_SPE;
	SPI1->CR1 |= SPI_CR1_CSTART;
	while((SPI1->SR & SPI_SR_TXP) != 0)
	{
		*((__IO uint8_t *)&SPI1->TXDR) = 0xFF;
		Serial1.println("SPI.write");
	}

	Serial1.print("SPI1->CR1: "); Serial1.println(SPI1->CR1, HEX);
	Serial1.print("SPI1->CR2: "); Serial1.println(SPI1->CR2, HEX);
	Serial1.print("SPI1->CFG1: "); Serial1.println(SPI1->CFG1, HEX);
	Serial1.print("SPI1->CFG2: "); Serial1.println(SPI1->CFG2, HEX);
	Serial1.print("SPI1->IER: "); Serial1.println(SPI1->IER, HEX);

	Serial1.print("RCC->AHB1RSTR: "); Serial1.println(RCC->AHB1RSTR, HEX);
	Serial1.print("RCC->AHB2RSTR: "); Serial1.println(RCC->AHB2RSTR, HEX);
	Serial1.print("RCC->APB1LRSTR: "); Serial1.println(RCC->APB1LRSTR, HEX);
	Serial1.print("RCC->APB1HRSTR: "); Serial1.println(RCC->APB1HRSTR, HEX);
	Serial1.print("RCC->APB2RSTR: "); Serial1.println(RCC->APB2RSTR, HEX);
	Serial1.print("RCC->APB3RSTR: "); Serial1.println(RCC->APB3RSTR, HEX);
	Serial1.print("RCC->AHB1ENR: "); Serial1.println(RCC->AHB1ENR, HEX);
	Serial1.print("RCC->AHB2ENR: "); Serial1.println(RCC->AHB2ENR, HEX);
	Serial1.print("RCC->APB1LENR: "); Serial1.println(RCC->APB1LENR, HEX);
	Serial1.print("RCC->APB1HENR: "); Serial1.println(RCC->APB1HENR, HEX);
	Serial1.print("RCC->APB2ENR: "); Serial1.println(RCC->APB2ENR, HEX);
	Serial1.print("RCC->APB3ENR: "); Serial1.println(RCC->APB3ENR, HEX);

	Serial1.print("GPIOA->MODER: "); Serial1.println(GPIOA->MODER, HEX);
	Serial1.print("GPIOA->AFRL: "); Serial1.println(GPIOA->AFR[0], HEX);
	Serial1.print("GPIOA->AFRH: "); Serial1.println(GPIOA->AFR[1], HEX);
	Serial1.print("GPIOB->MODER: "); Serial1.println(GPIOB->MODER, HEX);
	Serial1.print("GPIOB->AFRL: "); Serial1.println(GPIOB->AFR[0], HEX);
	Serial1.print("GPIOB->AFRH: "); Serial1.println(GPIOB->AFR[1], HEX);
	Serial1.print("GPIOC->MODER: "); Serial1.println(GPIOC->MODER, HEX);
	Serial1.print("GPIOC->AFRL: "); Serial1.println(GPIOC->AFR[0], HEX);
	Serial1.print("GPIOC->AFRH: "); Serial1.println(GPIOC->AFR[1], HEX);

	while((SPI1->SR & SPI_SR_RXP) == 0)
	{
		Serial1.print("SPI1->SR: "); Serial1.println(SPI1->SR, HEX);
		delay(1000);
	}

	(void)*((__IO uint8_t *)&SPI1->RXDR);

	//SPI.transfer(0xAA);
	Serial1.print("loop end: ");
	Serial1.println(millis());
}

 

 

What I see: the pins are set up, the peripheral module is set up, I fill the FIFO completely, but nothing is sent.

Debug output:

 

 

loop begin: 0
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI.write
SPI1->CR1: 1201
SPI1->CR2: 0
SPI1->CFG1: 50070007
SPI1->CFG2: 84400000
SPI1->IER: 0
RCC->AHB1RSTR: 0
RCC->AHB2RSTR: 0
RCC->APB1LRSTR: 0
RCC->APB1HRSTR: 0
RCC->APB2RSTR: 0
RCC->APB3RSTR: 0
RCC->AHB1ENR: 90001100
RCC->AHB2ENR: 40000001
RCC->APB1LENR: 0
RCC->APB1HENR: 0
RCC->APB2ENR: 5000
RCC->APB3ENR: 0
GPIOA->MODER: ABFFABEB
GPIOA->AFRL: 55500880
GPIOA->AFRH: 0
GPIOB->MODER: FF33FEBF
GPIOB->AFRL: FF33FEBF
GPIOB->AFRH: FF33FEBF
GPIOC->MODER: FFFFFFFF
GPIOC->AFRL: FFFFFFFF
GPIOC->AFRH: FFFFFFFF
SPI1->SR: 0
SPI1->SR: 0
SPI1->SR: 0
SPI1->SR: 0
SPI1->SR: 0
SPI1->SR: 0

 

 

I can't figure out where the mistake is. I'd appreciate any hints.

1 ACCEPTED SOLUTION

Accepted Solutions
smalcom1
Associate

The problem is solved. By default, stm32duino sets the system clocking from PLL1P. And SPI1 cannot use this signal as a source. I switched SPI1 to clocking from PER_CK and everything worked.

View solution in original post

2 REPLIES 2
smalcom1
Associate

The problem is solved. By default, stm32duino sets the system clocking from PLL1P. And SPI1 cannot use this signal as a source. I switched SPI1 to clocking from PER_CK and everything worked.

Thanks for coming back with the solution. Please click on "Accept as solution" in that post so that the thread is marked as solved. You may perhaps report this also on the STM32duino forum.

JW