AnsweredAssumed Answered

STM32L0 SPI + DMA + interrupts = Problem

Question asked by woj.woj on Feb 28, 2016
Latest reply on Mar 2, 2016 by woj.woj
Hallo,
I have a problem with SPI and DMA in interrupt mode. on my stm32l053. When I start SPI transmition, SCK and NSS pins looks ok, but there is nothing at MOSI line. I checked DR register but it is 0 during whole transmition. At the end I receive TCI interrupt from DMA (what would suggest that it transmited some data from memory to SPI_DR).
Below DMA Initialization:
void MX_DMA_Init(void)
{
  __DMA1_CLK_ENABLE();

  //Channel2 Rx
  DMA1_Channel2->CCR |= (1 << MINC) | (1 << CIRC) |
          (1 << TCIE);
  DMA1_Channel3->CCR |= (1 << MINC) | (1 << CIRC) |
          (1 << TCIE) | (1 << DIR);

//  DMA1_Channel2->CNDTR = 5;
//  DMA1_Channel3->CNDTR = 5;

  DMA1_Channel2->CPAR = (uint32_t)(&(SPI1->DR));
  DMA1_Channel3->CPAR = (uint32_t)(&(SPI1->DR));

  DMA1_Channel2->CMAR = (uint32_t)(rxBuff);
  DMA1_Channel3->CMAR = (uint32_t)(txBuff);

  DMA1_CSELR->CSELR |= (1 << C2S0) | (1 << C3S0);

  /* DMA interrupt init */
  HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
}

SPI Initialization

void MX_SPI1_Init(void)
{
    __SPI1_CLK_ENABLE();
    SPI1->CR1 |= (1 << BR2) | (1 << CPHA) |
            (1 << MSTR) | (1 << SSM) | (1 << SSI) | (1 << CPOL) | (1 << CPHA);
    SPI1->CR2 |= ( 1 << SSOE);
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
    SPI1->CR2 |= (1 << TXEIE) | (1 << RXNEIE);
//    HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
//    HAL_NVIC_EnableIRQ(SPI1_IRQn);
}

and ISR for DMA TCIE

void DMA1_Channel2_3_IRQHandler(void)
{
    if((DMA1->ISR >> TCIF3) & 1)
    {
        DMA1_Channel3->CCR &= ~(1 << EN);
        DMA1->IFCR |= (1 << CTCIF3);
    }
    if((DMA1->ISR >> TCIF2) & 1)
    {
        DMA1_Channel2->CCR &= ~(1 << EN);
        DMA1->IFCR |= (1 << CTCIF2);
        while((SPI1->SR) >> BSY){}
        StopSPI();
    }
}
Could anybody suggest where to look for a problem?
Regards

Outcomes