cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 spi dma circular mode for external ADC 2M Sampling

Fish
Associate II

hi,

i'm trying to read the external adc value using spi1 + dma (MAX11198ATE+)

i though it works fine but, sometimes it returns wrong values

i have checked the waveforms of SPI MISO/MOSI, SCK (hardware)

but there was no error forms. it seems to be matched in timing chart

@@

i have checked spi mode and tested this for TI mode (hardware output NSS) and motorola mode (in this case, NSS was not Used)

but result was same

@@

there was no effect for changing the compile optimization level 0 ~ 3

when i debugging the firmware source, rx buffer for spi dma is below

(1)

desiable return value range : 0xD2E0 ~ 0x D310

(2)

wrong value : 0xD200 or D3FE~F

you can see the below image

look at the buffer index [1] / [20]

it seems to be fluctuated (low byte units or middle 1 bits)

i don't know what happens

i just called hal libray for reading value using spi..

there was no custom library..

and i have read the m4 reference manual many times

but i don't undertand..

here is my initial setting code on spi dma

first,

i have set the main system clock '128MHz' and APB2 '64MHz' due to spi1 sck clock for 32MHz

second,

spi + tx / rx dma settings with circular mode

//------------------------------------------------------------------------------------
 
  /* SPI1 DMA Init */
 
  /* SPI1_RX First Init Befor Tx Init */
 
  hdma_spi1_rx.Instance        = DMA2_Stream0;
 
  hdma_spi1_rx.Init.Channel      = DMA_CHANNEL_3;
 
  hdma_spi1_rx.Init.Direction     = DMA_PERIPH_TO_MEMORY; 
 
  hdma_spi1_rx.Init.PeriphInc     = DMA_PINC_DISABLE; 
 
  hdma_spi1_rx.Init.MemInc       = DMA_MINC_ENABLE;
 
  hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 
  hdma_spi1_rx.Init.MemDataAlignment  = DMA_MDATAALIGN_HALFWORD;
 
  
 
  hdma_spi1_rx.Init.Mode       = DMA_CIRCULAR;
 
  hdma_spi1_rx.Init.Priority      = DMA_PRIORITY_VERY_HIGH;
 
  hdma_spi1_rx.Init.FIFOMode  = DMA_FIFOMODE_DISABLE;
 
 
 
  if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
 
  {
 
   Error_Handler();
 
  }
 
 
 
  __HAL_LINKDMA(spiHandle, hdmarx, hdma_spi1_rx);
 
 
 
  /* SPI1_TX Init */
 
  hdma_spi1_tx.Instance        = DMA2_Stream3;
 
  hdma_spi1_tx.Init.Channel      = DMA_CHANNEL_3;
 
  hdma_spi1_tx.Init.Direction     = DMA_MEMORY_TO_PERIPH;
 
  hdma_spi1_tx.Init.PeriphInc     = DMA_PINC_DISABLE;
 
  hdma_spi1_tx.Init.MemInc       = DMA_MINC_ENABLE;
 
  hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
 
  hdma_spi1_tx.Init.MemDataAlignment  = DMA_MDATAALIGN_HALFWORD;
 
  hdma_spi1_tx.Init.Mode       = DMA_CIRCULAR;  
 
  hdma_spi1_tx.Init.Priority      = DMA_PRIORITY_VERY_HIGH;
 
  hdma_spi1_tx.Init.FIFOMode   = DMA_FIFOMODE_DISABLE;
 
  
 
  if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)
 
  {
 
   Error_Handler();
 
  }
 
 
 
  __HAL_LINKDMA(spiHandle, hdmatx, hdma_spi1_tx);
 
 
 
  /* SPI1 interrupt Init */
 
  HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
 
  HAL_NVIC_EnableIRQ(SPI1_IRQn);
 
//------------------------------------------------------------------------------------
 

after the code periperal is set, i called

hal_spi_transmitreceive_dma(...)

also, either dma fifor setting enable or not was not affected in the result

anyone help

thanks

0 REPLIES 0