I am using SPI1 DMA for sending data from STM32F446RET6 to Nokia5110 LCD. But it doesn’t work. When I try without DMA, it works. Is my program wrong? Full program can be downloaded via the following link. It can be opened with STM32 Cube IDE. https://easyupload.io/m78pr9
static void initSPI1(void)
{
// PA5, PA6, PA7 AS AF7
RCC->AHB1ENR |= 1<<0;
GPIOA->MODER &= ~(1<<10 | 1<<12 | 1<<14);
GPIOA->MODER |= 1<<11 | 1<<13 | 1<<15;
GPIOA->AFR[0] |= 1<<20 | 1<<22 | 1<<24 | 1<<26 | 1<<28 | 1<<30;
// SPI1 CONFIG
RCC->APB2ENR |= 1<<12;
SPI1->CR1 |= 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<8 | 1<<9;
SPI1->CR2 |= 1<<1; // ENABLE TX DMA
SPI1->CR1 |= 1<<6; // ENABLE SPI1
// DMA2 CONFIG
RCC->AHB1ENR |= 1<<22;
DMA2_Stream3->CR |= 1<<4 | 1<<6 | 1<<8 | 1<<10 | 1<<25 | 1<<26;
}
static void sendChar(char character)
{
GPIOA->ODR &= ~(1<<0); // CS_PIN_LOW
DMA2_Stream3->NDTR = 1;
DMA2_Stream3->PAR = (uint32_t) &SPI1->DR;
DMA2_Stream3->M0AR = (uint32_t) character;
DMA2_Stream3->CR |= 1<<0;
while(!(DMA2->LISR & 1<<27));
DMA2_Stream3->CR &= ~(1<<0);
DMA2->LIFCR |= 1<<27;
// send char without dma
// SPI1->DR = character;
// while(!(SPI1->SR & 1<<1));
// while(SPI1->SR & 1<<7);
//
// (void) SPI1->DR;
// (void) SPI1->SR;
GPIOA->ODR |= 1<<0; // CS_PIN_HIGH
}