cancel
Showing results for 
Search instead for 
Did you mean: 

DMA to external DAC transfer via SPI communication

franck2
Associate II
Posted on November 13, 2014 at 13:32

Hi everybody,

I'm a beginner with STM32F30x µP. I'd like to made a DMA transfers from SRAM to an external DAC via SPI communication. Is it possible? Can I even configure a timer (TIMx) to generate a PWM signal or One Pulse Mode signal on TIMx_CHx and use it as DMA trigger and also as NSS signal input to latch the SPI data transfers to my external DAC?

Thanks for your advice on that point.

Regards,

Franck
19 REPLIES 19
franck2
Associate II
Posted on November 19, 2014 at 23:48

Hi Linas,

Many thanks for the post.

Franck

franck2
Associate II
Posted on November 20, 2014 at 22:15

Hi Guys,

While looking for some programs example on the forum, i found the following [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32%20SPI%20DMA%20for%20External%20SPI%20DAC&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=550]link which is more or less what i'm looking for; i.e to stream 16-bit or even 32-bit word data to an external DAC, with no sweat for the processor and  doing so by timer triggered DMA transfers to SPI as a viable option.

I'm coding and will share with everybody asap.

Best regards,

Franck

franck2
Associate II
Posted on November 26, 2014 at 11:17

Hi everybody,

As suggested by Jan, I divide the problem in three part: first, learn to set up the timer, then leran to set up SPI with ''manual'' ''filling'' of data register, and then learn to set up the DMA.'' The first part is completed as I am able to set two Timer in PWM mode. (See attachment). Now configuring the SPI I have many questions:

1- Should I define the NSS, SCK,MISO, MOSI pins as follow:

/* GPIOA, GPIOB & GPIOC Clocks enable */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB |RCC_AHBPeriph_GPIOC, ENABLE);

    

/********************************************SPI Configuration*************************************/    

    /*Configuration pins used by SP2:

    * SPI2_NSS = PB12

    * SPI2_SCK = PB13

    * SPI2_MISO = PB14 //for FULL DUPLEX; Will not be used in our case?

    * SPI2_MOSI = PB15 */

    

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;

    

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_5); //NSS  PB12 AF5

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_5); //SCK  PB13 AF5

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_5); //MISO PB14 AF5

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_5); //MOSI PB15 AF5

2- Knowing that I'll be in simplex mode ( The SPI will only transmit data => RXONLY=0 of SPI2_CR2 register), and that I want a DMA TIM triggered on SPI, should I used the DMA Tx?

I'm getting confused on that point.

The rerence Manual says on that point:

''When starting communication using DMA...these steps must be followed in order:

* Enable DMA Rx buffer....not my case as DMA_Rx is unused in my case

*Enable DMA streams for Tx and Rx in DMA registers, if the streams are used (Yes)

*Enable DMA Tx buffer in the TXDMAEN bit in the SPI_CR2 register, if DMA_Tx is used

*Enable the SPI by setting the SPE bit.

3- So, as in my case it is the DMA which is triggered by a timer and send datas taken in SRAM to SPI should i define the SPI as usual in a normal way enabeling the clock, the mode, data size, clock phase and polarity controls,data frame format......

Thanks for your feedback on that points.

Franck

franck2
Associate II
franck2
Associate II
Posted on November 26, 2014 at 15:50

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bp&d=%2Fa%2F0X0000000brk%2F3cpcapScbjrp0ymtfzG2rB_Kpe7F1hhwBuPaVUPuG5A&asPdf=false
franck2
Associate II
franck2
Associate II
Posted on November 27, 2014 at 18:56

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6gX&d=%2Fa%2F0X0000000btB%2FFgzGhhio03TIJJGB0FuH4acqMC5d5FJ_fvHZY05pzEI&asPdf=false
franck2
Associate II
Posted on November 28, 2014 at 14:51

Any Help?

I'm stuck....

Thanks

franck2
Associate II
Posted on November 28, 2014 at 15:27

i've add a buffer:

uint16_t TxBuffer[32] = {

                        0xAAAA, 0xAAAB, 0xAAAC, 0xAAAD, 0xAAAE, 0xAAAF, 0xAAB0, 0xAAB1,

                        0xAAB2, 0xAAB3, 0xAAB4, 0xAAB5, 0xAAB6, 0xAAB7, 0xAAB8, 0xAAB9,

                        0xAABA, 0xAABB, 0xAABC, 0xAABD, 0xAABE, 0xAABF, 0xAAC0, 0xAAC1,

                        0xAAC2, 0xAAC3, 0xAAC4, 0xAAC5, 0xAAC6, 0xAAC7, 0xAAC8, 0xAAC9};

uint16_t TTxBuffer[32];   

I manage it:

int main(void)

{

    uint8_t Idx = 0;

  /*!< At this stage the microcontroller clock setting is already configured,

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f30x.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f30x.c file

     */

 

    /* Fill TTxBuffer table */

    for (Idx = 0; Idx <32; Idx++)

        {

            TTxBuffer[Idx] = TxBuffer[Idx] ;

        }

In debug mode looking at the SPI2 the SPI2 data Register is empty.

I don't understand why?

Thanks for your help

franck2
Associate II
Posted on December 15, 2014 at 10:39

See solution [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Is%20there%20anaybody%20that%20have%20a%20TIM%20triggered%20DMA%20working%20Code&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=110]here