• AVR Freaks

Hot!dsPIC33 DMA SPI problem

Author
MateuszPaczynski
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/06/05 07:31:27
  • Location: 0
  • Status: offline
2018/06/06 02:05:18 (permalink)
0

dsPIC33 DMA SPI problem

Dear All,
 
I tried to implement a simple program to learn how to use a DMA feature. I planned to send data to DMA, and I hoped that DMA will automatically send data to the SPI buffer. 
Firstly, I have checked an SPI functionality. It was sending data to the sensor as I wanted. After that, I tried to add a DMA functionality. Unfortunately, I failed and I didn't manage to send any data.
 
I am working a dsPIC33EP128EP204 processor. Configuration was generated with MCC help. Please find my code (full code in attachments) :
 
int main(void)
{
SYSTEM_Initialize();

// Enable the Global Interrupts
INTERRUPT_GlobalEnable();

DMA_PeripheralAddressSet(0,&SPI1BUF);
DMA_PeripheralIrqNumberSet(0,10);
DMA_TransferCountSet(0,1);
DMA_ChannelEnable(0);

/*
DMA0REQbits.FORCE=1;
while (DMA0REQbits.FORCE == 1);
IEC0bits.SPI1IE = 1;
*/

DMA_SoftwareTriggerEnable(0);
DMA_FlagInterruptClear(0);

while (1)
{
//SPI1_Exchange16bit(0xAAaa);
// Add your application code
}

return 0;
}
 
I will be grateful for any help.
Sincerely xyz
#1

9 Replies Related Threads

    RISC
    Super Member
    • Total Posts : 5376
    • Reward points : 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2018/06/10 15:20:52 (permalink)
    0
    Hi,
    Please find herewith the code example CE416 for SPI with DMA on dsPIC33EP
    Regards
    #2
    pr.mchp
    Starting Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2015/03/23 06:20:48
    • Location: 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2018/07/12 03:18:14 (permalink)
    0
    Hi
    SPI in MCC is supported for Enhanced mode of Operation only.
    In case of DMA functionality, SPI should be in standard mode only.(Refer FRM for more information).
     
    Thanks
    MCC Team
     
     
     
    #3
    rangel
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2015/02/24 08:21:23
    • Location: 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/11 13:13:10 (permalink)
    0
    Hi pr.mchp,
     
    I read all frms and could not make the dma with spi work yet.
    The example in DS70005185A-page 34 are, in part, wrong.
     
    Without dma, the spi are workink and i am using enhanced buffer.
     
    In DS70005185A-page 2 say: When using the SPI module with DMA, the FIFO operation can be disabled.
    In DS70005185A-page 33 say: When using the SPIx module with DMA, the SPIBEN bit can be programmed to ‘0’, thereby disabling FIFO operation.
    "CAN" != "SHOULD".
    The frms should be clearer, and with better, correct and more code examples.
     
    And if the dma not work with enhanced buffer, this seems to me like a big project bug.
     
    Why "SPI2STATbits.SISEL" in 4 or 6 mode can not be used to trigger a dma request ?
     
    SPI2STATbits.SISEL = 4; // mode = 4 -> Interrupt when one data is shifted into the SPIxSR and as a result, the TX FIFO has one open memory location.
    // mode = 6 -> Interrupt when last bit is shifted into SPIxSR and as a result, the TX FIFO is empty.
    // For DMA configuration, trigger a dma request ??????

    Summarize:
     
    * I only need master transmit mode with dma !!!!
    * I need setup two dma channels(1 receive and 1 transmit) to spi work with dma in master transmit only ?
    * I need to enable spi interrupt ? (Example code in DS70005185A-page 34 and page 35 are enabled). In UARt dma i dont need enable tx interrupt. I only set "Interrupt after one TX character is transmitted. For DMA configuration, trigger a DMA request".
    * SPI with dma need to disable enhanced buffer mode ?

    Notes:
    * In another project a few years ago, i have already been able to configure uart transmitter using DMA and it worked perfectly.
    * I dont use MCC, i use "pure" XC16.
    * dspic33ep512mc502.
     
    Thank's.
    post edited by rangel - 2019/04/11 13:15:08
    #4
    rangel
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2015/02/24 08:21:23
    • Location: 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/11 16:28:42 (permalink)
    0
    Hi,
     
    I disabled the enhanced buffer and i dont enable spi interrupt in my code, now the spi are outputting 3 bytes and stop, even my buffer being larger.
     
    I think that receive buffer are overflowing.
    I will verify.
     
    * Without dma and with enhanced buffer enabled the spi work without i need to read spi2buf.

    * Without dma and with enhanced buffer disabled the spi send only one byte and stop if i dont read spi2buf.

    Strange behavior.
     
    Thank's.
    #5
    rangel
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2015/02/24 08:21:23
    • Location: 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/11 17:20:14 (permalink)
    0
    Hi,
     
    I wrote a program to verify the DMA0CNT after spi sending 3 bytes and stop and the result was DMA0CNT = 11.
    I send a buffer with 11 elements.  
     

    for( i = 0 ; i <= DMA0CNT ; i++ )
    {
            led = ~led;
            delay_seg(1);
            led = ~led;
            delay_seg(1);
    }

    post edited by rangel - 2019/04/11 17:22:12
    #6
    rangel
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2015/02/24 08:21:23
    • Location: 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/11 19:20:30 (permalink)
    0
    Hi,
     
    It worked.
     
    I was forced to use another dma channel to receive data because there was overflow.
     
    As a suggestion:
     
    There could be an option to just transmit, just receive and another option for both, maybe in master and slave modes.
     
    Just transmit could disable receive overflow, so one dma channel would be possible and the reception of data would not have to generate interruption, although I configured to generate interrupt every 16383 bytes received.
     
    I also configured "Register Indirect without Post-Increment mode" and "Continuous, Ping-Pong modes disabled" soh i only allocate a "buffer" with one single position.  
     
    #7
    Aussie Susan
    Super Member
    • Total Posts : 3591
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/14 19:14:58 (permalink)
    0
    The 'just receive' is covered by using the 'NULLW' option.
    You need to be careful with the 'just transmit' option because the exchange is NOT complete when the value is transferred to the shift register - therefore is is best to use the Rx side for triggering the next DMA transfer.
    Therefore it is just as easy to set up a dual -channel DMA. Of course you can have the Rx DMA channel set up to no increment the address value so you continuously write to the same (dummy) location. AS it is only the hardware doing the work, there is really no penalty.
    Some of the newer MCU DMAs do have the type of thing you are after.
    Susan
    #8
    rangel
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2015/02/24 08:21:23
    • Location: 0
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/15 12:31:01 (permalink)
    0
    Hi Aussie Susan,
     
    The 'just receive' is covered by using the 'NULLW' option.
    Answer: Yes, i had read and had forgotten.

    You need to be careful with the 'just transmit' option because the exchange is NOT complete when the value is transferred to the shift register - therefore is is best to use the Rx side for triggering the next DMA transfer.
    Answer: At the moment i'm checking SPITBF and CHEN.

    Therefore it is just as easy to set up a dual -channel DMA. Of course you can have the Rx DMA channel set up to no increment the address value so you continuously write to the same (dummy) location. AS it is only the hardware doing the work, there is really no penalty.
    Answer: Yes. I'm doing this. And i setting the receiving dma counter to max value(16383) to interrupt cpu few times. Now i thinkink that i can disable dma receiving interrupt too. I will try.

    Some of the newer MCU DMAs do have the type of thing you are after.
     
    Susan
    #9
    Aussie Susan
    Super Member
    • Total Posts : 3591
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: dsPIC33 DMA SPI problem 2019/04/15 19:30:55 (permalink)
    0
    Possible a side issue but who are we actually helping here. The OP ('MatueszPaczynski') has only 1 post against their name and all of the other posts that seem to be replying to our suggestions etc. come from 'Rangel'.
    Are we even dealing with the same MCU, code sample and problem?
    Also there does not appear to be a dsPIC33EP128EP204 - there is a dsPIC33EP128MC204 so I assume that the first one was a typo.
    I think we need to get a few concepts clear (and possibly correct a misconception that I may have introduced for this MCU).
    When using DMA with a module, you should not enable the module interrupts as the DMA controller will use the required flags to 'know' when each value transfer/exchange is complete. The DMA module itself also has interrupts that can let you know when a complete transfer (multiple values) has completed.
    With the SPI module on this MCU (and here is where I may have misled you a bit by getting mixed up with some other MCUs), the DMA controller is only signalled when an exchange is complete and there fore the module is ready for another exchange is necessary. The reason you may want two DMA channels is to have the higher priority one read the last exchanged value into a buffer before the lower priority channel initiates the next exchange.
    You should not be interfering with this process (which is why you should NOT enable the SPI module interrupts). This implies that you should not be doing anything with the SPITBF bit.
    Similarly, the CHEN bit is only used to control the DMA channel. IF you have set it up for one-shot then it will be cleared when the transfer is complete. You can monitor this for yourself but that negates the advantage of using DMA in the first place. Use the DMA interrupt to know when the transfer is complete.
    Of course if you don't care when a channel completes the transfers, then don't enable the DMA interrupt. Just let it  complete or, if you have set it to be on-going, disable it whenever the conditions are right.
    People get into problems with using DMA when they try to become  too involved with the process. The DMA controller is designed to do the work for you and so you need to initialise the DMA controller channel and the peripheral, and then let them get on with the work.
    Susan
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5