AnsweredAssumed Answered

ADuCM320 DMA SPI issue

Question asked by sigpipe on Sep 4, 2017
Latest reply on Nov 13, 2017 by sigpipe

Hi,

I'm trying to understand SPI Transfers using DMA. SPI is used as master and I'm only sending via MOSI, MISO isn't used. So I assume, I only need 1 DMA channel and did the following setup:

 

/* somewhere in chip initialisation: */

    DmaBase();

    DmaPeripheralStructSetup(SPI0TX_C, DMA_DSTINC_NO | DMA_SRCINC_HWORD | DMA_SIZE_HWORD);

 

/* send routine - sends out a frame with len size*/

void send(uint8_t *buffer, uint32_t size) {
    uint32_t pSize = size >> 1;
    if (size & (1<<0)) pSize++;

 

    SpiDma(pADI_SPI0, SPIDMA_IENRXDMA_DIS, SPIDMA_IENTXDMA_DIS, SPIDMA_ENABLE_DIS);
    DmaStructPtrOutSetup(SPI0TX_C, pSize, buffer);
    DmaGo(SPI0TX_C, pSize, DMA_BASIC);
    DmaSet(0, SPI0TX_B, 0, 0);
    SpiCount(pADI_SPI0, size, 1);
    SpiDma(pADI_SPI0, SPIDMA_IENRXDMA_DIS, SPIDMA_IENTXDMA_EN, SPIDMA_ENABLE_EN);
}

 

This code works for any value of size from 1 to 6 (which is the size I need).

 

I have an "send frame" function, which generates a 4 byte frame:

 

uint8_t spiTxBuffer[4];

void sendFrameType12(uint8_t data1, int16_t data2) {
    spiTxBuffer[0] = 0x12;
    spiTxBuffer[1] = data1;
    spiTxBuffer[2] = (data2 >> 8) & 0xff;
    spiTxBuffer[3] = data2 & 0xff;
    arcCommSend(buffer, 4);

}

 

Strangely, this function will result in a [0x00][0x12][0x66][0x00] (for data1==0x66).

 

Do I miss something here? If I call the send routine directly from main, data on SPI is as expected.

 

thanks

Outcomes