This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: SPI Continuously Read DMA Example?

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE

Hi all!

I was trying to read N words from SPI with DMA continuously. But I couldn't find a proper example in C2000Ware folder.

I tried to modify spi_ex5_loopback_dma example but couldn't configure it as I want. Basically, I want to triger DMA in software to start reading N word from spi and want to get interrupt when the words are read and written to the speecified to memory region.

Can anybody help me about that?

cheers,

  • Hi,

    The spi_ex5_loopback_dma example configures both SPI TX and RX data transfers. The trigger is the TX and RX events respectively. It also shows how to configure DMA interrupt at the end of the transfer.

    Let me know if you are facing any issues while using the example.

    Regards,

    Veena

  • Hi Veena!

    Thanks for your answer. Yes I tried this example it works well in loop back mode. But that doesn't help me. Then I derived this example for my goal. My setup is simple. I use control card with dock station. And i use gpio17 as MISO for SPIA. I dont have any slave device. I connect MISO to either VCC or GND. I share my code below. I just want to read N bytes from SPI with DMA. I trigger the DMA and it reads SPI then I got interrupt but the data bytes are always 0.

    Could you please check the code and tell me what is wrong? 

    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include "board.h"
    
    //
    // Defines
    //
    #define FIFO_LVL 8 // FIFO interrupt level
    #define BURST FIFO_LVL // Each burst will empty the FIFO
    #define TRANSFER 4 // It will take 16 bursts of 8 to transfer
    #define BUFF_SIZE 32U // all data in rData
    
    //
    // Globals
    //
    uint16_t rData[BUFF_SIZE]; // Send data buffer
    
    // Place buffers in GSRAM
    #pragma DATA_SECTION(rData, "ramgs1");
    
    
    volatile uint16_t done = 0; // Flag to set when all data transferred
    
    //
    // Function Prototypes
    //
    void initDMA(void);
    void initSPIFIFO(void);
    void PinMux_initt();
    __interrupt void dmaCh6ISR(void);
    
    // This example use SPI and CLB together to read simultaneous data from 2 spi devices.
    // SPI reads data 16bit at once. At every 2 reads of SPI CLB push the 32 bit(2 x 16bit) to the exchange3 memory which has 4 word(32bit) length.
    
    void main(void)
    {
    uint16_t erhan;
    Device_init();
    Device_initGPIO();
    
    Board_init();
    
    PinMux_initt();
    
    
    //
    // Initialize PIE and clear PIE registers. Disables CPU interrupts.
    //
    Interrupt_initModule();
    
    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    //
    Interrupt_initVectorTable();
    
    //
    // Interrupts that are used in this example are re-mapped to ISR functions
    // found within this file.
    //
    Interrupt_register(INT_DMA_CH6, &dmaCh6ISR);
    
    //
    // Set up DMA for SPI use, initialize the SPI for FIFO mode
    //
    initDMA();
    initSPIFIFO();
    
    
    //
    // Initialize the data buffers
    //
    for(erhan = 0; erhan < BUFF_SIZE; erhan++)
    {
    rData[erhan]= 0;
    }
    
    //
    // Enable interrupts required for this example
    //
    Interrupt_enable(INT_DMA_CH6);
    
    //
    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    //
    EINT;
    ERTM;
    
    
    
    
    initSPIFIFO();
    
    
    while(1)
    {
    
    done=0;
    
    DMA_startChannel(DMA_CH6_BASE);
    
    while(!done) // wait until the DMA transfer is complete
    {
    DMA_forceTrigger(DMA_CH6_BASE);
    
    asm(" RPT #255 || NOP");
    }
    
    }
    }
    
    void PinMux_initt()
    {
    //
    // SPIA -> mySPI0 Pinmux
    //
    GPIO_setPinConfig(GPIO_16_SPIA_SIMO);
    GPIO_setPinConfig(GPIO_17_SPIA_SOMI);
    GPIO_setPinConfig(GPIO_18_SPIA_CLK);
    GPIO_setPinConfig(GPIO_19_SPIA_STEN);
    
    }
    
    //
    // Function to configure SPI A in FIFO mode.
    //
    void initSPIFIFO()
    {
    //
    // Must put SPI into reset before configuring it
    //
    SPI_disableModule(SPIA_BASE);
    
    //
    // FIFO configuration
    //
    SPI_enableFIFO(SPIA_BASE);
    SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
    SPI_setFIFOInterruptLevel(SPIA_BASE, (SPI_TxFIFOLevel)FIFO_LVL,
    (SPI_RxFIFOLevel)FIFO_LVL);
    
    //
    // SPI configuration. Use a 1MHz SPICLK and 16-bit word size.
    //
    SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,
    SPI_MODE_MASTER, 1000000,16);
    SPI_enableModule(SPIA_BASE);
    }
    
    //
    // DMA setup for both TX and RX channels.
    //
    void initDMA()
    {
    //
    // Initialize DMA
    //
    DMA_initController();
    
    //
    // Configure DMA Ch6 for RX. When the FIFO contains at least 8 words to
    // read, data will be transferred from the SPI module's receive buffer
    // register to the rData buffer.
    //
    DMA_configAddresses(DMA_CH6_BASE, rData,
    (uint16_t *)(SPIA_BASE + SPI_O_RXBUF));
    DMA_configBurst(DMA_CH6_BASE, BURST, 0, 1);
    DMA_configTransfer(DMA_CH6_BASE, TRANSFER, 0, 1);
    DMA_configMode(DMA_CH6_BASE, DMA_TRIGGER_SPIARX, DMA_CFG_ONESHOT_DISABLE |
    DMA_CFG_CONTINUOUS_DISABLE | DMA_CFG_SIZE_16BIT);
    
    //
    // Configure DMA Ch6 interrupts
    //
    DMA_setInterruptMode(DMA_CH6_BASE, DMA_INT_AT_END);
    DMA_enableInterrupt(DMA_CH6_BASE);
    DMA_enableTrigger(DMA_CH6_BASE);
    }
    
    
    
    //
    // DMA Channel 6 ISR
    //
    __interrupt void dmaCh6ISR(void)
    {
    
    DMA_stopChannel(DMA_CH6_BASE);
    
    SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
    
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP7);
    
    
    done = 1;
    return;
    }

  • IT seems I misunderstood the concept. I wanted to read data from SPI with DMA using one channel.Idid it but in the end of transaction the data is stored in rx fifo. Then i should read this data from fifo which is time consuming.

  • Hi Erhan,

    Apologies for the delayed response.

    Are you getting the DMA interrupt at the end of the transaction?

    Regards,

    Veena

  • Hi Veena!

    All good. It was my fault. I solved it now.

    cheers,