AnsweredAssumed Answered

SPI3 DMA breaks after first halfword

Question asked by joee on Mar 13, 2012
Latest reply on Mar 14, 2012 by joee
If I let run this DMA interrupts, without a while looop on the line
64 I get only first word transmitted. With a while loop it is always OK.What's wrong?

01.void dma_tx(uint16_t *rxbuf, uint16_t *txbuf, uint16_t count)
02.{
03.    DMA_InitTypeDef DMA_InitStructure;
04. 
05.         
06. 
07.        DMA_ClearITPendingBit(DMA2_IT_GL1);
08.        DMA_ClearITPendingBit(DMA2_IT_GL2);
09.        DMA_ClearFlag(DMA2_IT_GL1);
10.        DMA_ClearFlag(DMA2_IT_GL2);
11.         
12. 
13.        /* DMA Channel configuration ----------------------------------------------*/
14.        DMA_Cmd(DMA2_Channel1, DISABLE);
15.        //DMA_ITConfig(DMA2_Channel1, DMA_IT_TC/*| DMA_IT_HT| DMA_IT_TE*/, ENABLE);
16.        DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&(SPI3->DR));
17.        DMA_InitStructure.DMA_MemoryBaseAddr = (u32) rxbuf;
18.        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
19.        DMA_InitStructure.DMA_BufferSize = count;
20.        DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
21.        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
22.        DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
23.        DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
24.        DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
25.        DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
26.        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
27.        DMA_Init(DMA2_Channel1, &DMA_InitStructure);
28.         
29.         
30.         
31. 
32.        /* Dummy TX channel configuration */
33.        DMA_Cmd(DMA2_Channel2, DISABLE);
34.        //DMA_ITConfig(DMA2_Channel2, DMA_IT_TC/*| DMA_IT_HT| DMA_IT_TE*/, ENABLE);
35.        DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&(SPI3->DR));
36.        DMA_InitStructure.DMA_MemoryBaseAddr = (u32)(txbuf);
37.        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
38.        DMA_InitStructure.DMA_BufferSize = count;
39.        DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
40.        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
41.        DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
42.        DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
43.        DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
44.        DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
45.        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
46.        DMA_Init(DMA2_Channel2, &DMA_InitStructure);
47.         
48.         
49. 
50.        SPI3->SR &= ~SPI_SR_CRCERR;
51.        SPI3->CR1 &= ~(SPI_CR1_CRCNEXT | SPI_CR1_CRCEN);
52.        SPI_I2S_ClearFlag(SPI3, SPI_I2S_FLAG_RXNE);
53.        SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Tx, ENABLE);
54.        SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Rx, ENABLE);
55.        SPI_Cmd(SPI3, ENABLE);
56. 
57.        DMA_Cmd(DMA2_Channel1, ENABLE);
58.        DMA_Cmd(DMA2_Channel2, ENABLE);
59. 
60.         
61.         
62. 
63.        //while(1);
64.        while (DMA_GetFlagStatus(DMA2_FLAG_TC2) == RESET);
65. 
66.        //SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, DISABLE);
67. 
68.}

Attachments

Outcomes