2022-05-10 05:08 AM
I used this function to initialize and setup STM32H743IIT6 uC to work with SPI in master mode:
void InitSPI(void)
{
RCC->APB2ENR=0x00102000; //Enabling SPI45 clock (default: rcc_pclk2=25MHz)
SPI4->CFG1=0x30070007; //Baud rate = SPI clock / 16 = 1.5625 MHz, No CRC, 8 data bits
SPI4->CFG2=0x00C00000; //CPOL=0, CPHA=0, LSB first, Master SPI, Full-duplex
SPI4->CR2=0x00000000; //Size of transfer is unknown and should be 0 (EOT will never happen)
SPI4->IFCR=0x00000200; //Clear possible mode faults
SPI4->CR1=0x00000001; //Enabling SPI
SPI4->CR1=0x00000201; //Enabling data transmission
}
after initialization, I use this function to transceive data:
unsigned int TransceiveSPI(unsigned int TransmitSPIData)
{
while((SPI4->SR & SPI_TXD_REGISTER_EMPTY_MASK)==0); //Waiting for last transmission to complete
SPI4->TXDR=TransmitSPIData; //Set the new data to transmit
while (((SPI4->SR & SPI_RECEPTION_COMPLETE_MASK)==0));//Waiting for reception of new data
return SPI4->RXDR; //return the received data
}
but no data is transmitted (even if no CLOCK signal is available on the uC pin)! What is the problem?
2022-05-10 05:16 AM
Read out and check the SPI and relevant GPIO registers content.
Observe the delay needed between enabling peripheral clock, and writing to given peripheral's registers:
JW
2022-05-10 05:31 AM
There is about a 1-second delay between the initialization function and the first time that I want to send data through SPI.
2022-05-10 06:03 AM
There is no delay between these two lines:
> RCC->APB2ENR=0x00102000; //Enabling SPI45 clock (default: rcc_pclk2=25MHz)
> SPI4->CFG1=0x30070007; //Baud rate = SPI clock / 16 = 1.5625 MHz, No CRC, 8 data bits
so SPI4->CFG1 might get written while clock is not effectively enabled, yet.
Read out and check the SPI and relevant GPIO registers content.
JW
2022-05-10 06:42 AM
A 1-second delay was added but there is no positive effect :(
2022-05-10 09:42 AM
I am not familiar with the 'H7 SPI, and it's an overcomplicated beast; but generally, you should read out the SPI and GPIO registers content and check against expected values.
If everything matches, the next step is to play manually in debugger while observing pins using logic analyzer/oscilloscope, until you achieve the expected activity.
JW