SPI1+DMA1

General discussion on mikroPascal PRO for ARM.
Post Reply
Author
Message
Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

SPI1+DMA1

#1 Post by Vit2 » 25 Apr 2024 06:47

Hey, everybody!
It works, but not like this

Code: Select all

procedure SPI1_Write_DMA(dat: Word);
begin
  // Initialize DMA1 channel 3
  DMA1_CCR3.B0 := 0;              // Disable DMA channel
  DMA1_CPAR3 := DWORD(@SPI1_DR);  // Set peripheral address register to SPI1 data register address
  DMA1_CMAR3 := DWORD(@dat);      // Set memory address register to the address of the data to be transmitted
  DMA1_CNDTR3 := sizeof(256);     // Set the number of data items to be transferred (in this case, 256)
  
  // Configure DMA control register with specific settings
  // For SPI transmit: Memory to peripheral mode, increment memory pointer, circular mode disabled, transfer direction from memory to peripheral,
  // peripheral data size 16 bits, memory data size 16 bits, priority level high, transfer complete interrupt enabled
  DMA1_CCR3 := $00002AD1;
  
  // Enable SPI1 transmit DMA request
  SPI1_CR2.B1 := 1;   // Enable DMA request for TX buffer
  
  // Enable DMA channel 3
  DMA1_CCR3.B0 := 1;   // Enable DMA channel
  
  // Wait for DMA transfer completion
  while (DMA1_ISR and $00000800) <> 0 do;  // Wait for DMA transfer complete flag
  
  // Clear DMA transfer complete flag
  DMA1_IFCR := $0C000000;   // Clear DMA transfer complete interrupt flags
  
  // Disable DMA channel
  DMA1_CCR3.B0 := 0;   // Disable DMA channel
end;

procedure SPI1_DMAInit();
begin
  // Initialize SPI1 with specified configuration
  SPI1_Init_Advanced(_SPI_FPCLK_DIV2, _SPI_MASTER OR _SPI_8_BIT OR
                      _SPI_CLK_IDLE_HIGH OR _SPI_FIRST_CLK_EDGE_TRANSITION OR
                      _SPI_MSB_FIRST OR _SPI_SS_DISABLE OR _SPI_SSM_ENABLE OR
                      _SPI_SSI_1, @_GPIO_MODULE_SPI1_PA567);
  
  // Enable clock for DMA1
  RCC_AHBENR.B0 := 1; // Enable DMA1 clock
  
  // Configure SPI1
  SPI1_CR2 := $0000;  // Clear slave select and other parameters
end;

Post Reply

Return to “mikroPascal PRO for ARM General”