Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.

We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.

Thank you for your understanding.


This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to set up SPI? STM32h743ZI

I'm still beginner to programming STM32. I haven't been able to configure SPI for two weeks and don't understand what I am doing wrong. I dug up all the forums looking for an answer, but nothing helped to solve my problem. I checked the MOSI and SCK pin with an oscilloscope and there are no signals on these pins. I tried different ways to configure SPI but still nothing helped. Tried configuring for SPI1, SPI2, SPI3, SPI4, SPI5 etc, same problem. Everything works in HAL, but I want to understand what I am doing wrong using CMSIS. Please give me at least a little hint what I'm setting up wrong. I'm using STM32H743ZI debug board. I really hope for your help, thank you.

#include "main.h"
 
 
#define cs_set() GPIOC->BSRR |= GPIO_BSRR_BR11;
#define cs_reset() GPIOC->BSRR |= GPIO_BSRR_BS11;
 
void SPIinit (void);
void Settings7219 (void);
void SPITransmit (uint8_t adress, uint8_t data);
 
int main (void) {
	SPIinit();
	Settings7219();
	GPIOB->BSRR |= GPIO_BSRR_BS0;
	while(1){
 
	}
}
 
void SPITransmit (uint8_t adress, uint8_t data)
 {
	SPI3->CR1 |= SPI_CR1_CSTART;
	uint8_t tx_buffer[1] = {0};
	while (!(SPI3->SR & SPI_SR_TXP));
	cs_set(); // SS enable
	tx_buffer[0] = adress;
	SPI3->TXDR = tx_buffer[0];
	tx_buffer[0] = data;
	SPI3->TXDR = tx_buffer[0];
	cs_reset(); // SS disable
	SPI3->CR1 &= ~SPI_CR1_CSTART;
 }
 
void Settings7219 (void)
{
	SPITransmit(0x09, 0x00);       //  no decoding
	SPITransmit(0x0a, 0x01);       //  brightness
	SPITransmit(0x0b, 0x07);       //  scan limit = 8 LEDs
	SPITransmit(0x0c, 0x01);       //  power down =0,normal mode = 1
	SPITransmit(0x0f, 0x01);       //  no display test
}
 
 
 
 /*__________________________SPI_Conf____________________*/
void SPIinit (void){
	/*_______________________RCC_________________________*/
 
	RCC->AHB4ENR  |= RCC_AHB4ENR_GPIOCEN;
	RCC->AHB4ENR  |= RCC_AHB4ENR_GPIOBEN;
	RCC->APB1LENR |= RCC_APB1LENR_SPI3EN;
 
	/*_______________________SET_MODE_____________________*/
	GPIOC->MODER &= ~GPIO_MODER_MODE12;
	GPIOC->MODER &= ~GPIO_MODER_MODE11;
	GPIOC->MODER &= ~GPIO_MODER_MODE10;
	GPIOC->MODER |= GPIO_MODER_MODE12_1 | GPIO_MODER_MODE11_0 |  GPIO_MODER_MODE10_1;
	
	GPIOB->MODER &= ~GPIO_MODER_MODE0;
	GPIOB->MODER |= GPIO_MODER_MODE0_0;
	/*_____________________SET_AF_________________________*/
	GPIOC->AFR[1] |= GPIO_AFRH_AFSEL10_1 | GPIO_AFRH_AFSEL10_2;  // MOSI
	GPIOC->AFR[1] |= GPIO_AFRH_AFSEL12_1 | GPIO_AFRH_AFSEL12_2;  // SCK
 
	/*_____________________SET_SPI________________________*/
	SPI3->CFG1 |= SPI_CFG1_MBR_1;
	//SPI3->CFG1 |= SPI_CFG1_CRCEN;
	//SPI3->CFG1 |= SPI_CFG1_FTHLV_0;
	SPI3->CFG2 |= SPI_CFG2_MASTER;
	SPI3->CFG2 |= SPI_CFG2_COMM_0;
	SPI3->CFG2 |= SPI_CFG2_CPOL;
	//SPI3->CFG2 |= SPI_CFG2_SSOE;
	//SPI3->CFG2 |= SPI_CFG2_SSM;
	//SPI3->CFG2 |= SPI_CFG2_SSOM;
	//SPI3->CR2 |= SPI_CR2_TSIZE;
	//SPI3->CR2 |= SPI_CR2_TSER;
	//SPI3->IER |= SPI_IER_TXPIE;
	//SPI3->CR1 |= SPI_CR1_SSI;
	//SPI3->IER |= SPI_IER_TXTFIE;
	SPI3->CR1 |= SPI_CR1_SPE;
	NVIC_EnableIRQ(SPI3_IRQn);
}