Post Go back to editing

SPI DMA sends bytes twice

Category: Software
Product Number: EVAL-ADUCM362QSPZ

Hi! I am developing a program for the ADuCM362 eval board that utilizes the SPI DMA peripheral in ping-pong mode (only TX). I have been success full in generating SPI writes, however each byte is sent twice. For example the first value in the buffer is decimal 0 and the second is decimal 1. On the oscilloscope I will see "0x00" then "0x00" then the next value "0x01" and then "0x01" again. It doesn't matter what value is being sent nor by which DMA data structure.

I have set DST_SIZE, SRC_SIZE, DST_IN, and SRC_INC all to "byte" or 011. Is there any other SPI or DMA settings that could cause this? I am using the given ADuCM362 drivers and the setup code is shown below.

void SPI1_INIT() {
   SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_EN, SPICON_RFLUSH_EN);     /* Flush Tx and Rx FIFOs */
   SpiFifoFlush(pADI_SPI1, SPICON_TFLUSH_DIS, SPICON_RFLUSH_EN);     /* Flush Tx and Rx FIFOs */

   // Set mode for SPI1 pins
   DioCfgPin(pADI_GP0, PIN0, 1); // SPI1 MISO
   DioCfgPin(pADI_GP0, PIN1, 1); // SPI1 SCLK
   DioCfgPin(pADI_GP0, PIN2, 1); // SPI1 MOSI
   DioCfgPin(pADI_GP0, PIN3, 1); // SPI1 SS (NOTE: not broken out to anything on my board)

   // Set the SPI1 clock rate in master mode to 1MHz. (SPIDIV)
   SpiBaud(pADI_SPI1, 7, SPIDIV_BCRST_DIS);

   SpiCfg(pADI_SPI1, SPICON_MOD_TX1RX1, SPICON_MASEN_EN, SPICON_CON_EN | SPICON_LOOPBACK_DIS |
            SPICON_RXOF_DIS | SPICON_ZEN_DIS | SPICON_TIM_TXWR | SPICON_CPOL_LOW |
         SPICON_CPHA_SAMPLELEADING | SPICON_ENABLE_EN); // Configure SPI1 channel (SPICON)

   // These all act on the DmaStruct
   DmaPeripheralStructSetup(SPI1TX_C, DMA_DSTINC_NO | DMA_SRCINC_BYTE | DMA_SIZE_BYTE); // Setup SPI1 Tx DMA primary structure
   DmaStructPtrOutSetup(SPI1TX_C, SPI1_TX_BUFFER_SIZE, ucSPI1txPrim);
   DmaCycleCntCtrl(SPI1TX_C, SPI1_TX_BUFFER_SIZE, DMA_PING);

   DmaPeripheralStructSetup(SPI1TX_C+ALTERNATE, DMA_DSTINC_NO | DMA_SRCINC_BYTE | DMA_SIZE_BYTE); // Setup SPI1 Tx DMA alternate structure
   DmaStructPtrOutSetup(SPI1TX_C+ALTERNATE, SPI1_TX_BUFFER_SIZE, ucSPI1txAlt);
   DmaCycleCntCtrl(SPI1TX_C+ALTERNATE, SPI1_TX_BUFFER_SIZE, DMA_PING);

   DmaSet(0, DMAENSET_SPI1TX, 0, 0); // Enable DMA (DMAENSET)
   NVIC_EnableIRQ(DMA_SPI1_TX_IRQn);
}

void DMA_INIT() {
   DmaBase();
}
  • Hi cippy,

    Would it be possible to see the Tx buffer declarations you want to transmit (ucSPI1txPrim and ucSPI1txAlt)?

    You mention that you have set DST_SIZE, SRC_SIZE, DST_IN, and SRC_INC all to "byte" or 011, however byte is 00. In the code you have pasted the correct define is used *_BYTE. Can you please confirm which of the two statements is correct? DST_INC should be set DMA_DSTINC_NO.

    The drivers are based on the ADuCM360 and the ADuCM362 includes a larger amount of DMA channels. On the ADuCM360 the alternate structures had to be located at an address 0x100 bytes away from the primary structures. Due to the extra DMA channels on the ADuCM362 the alternate structures have to be located 0x200 bytes away. This can be implemented by modifying CCD_SIZE in the DMA library from 16 to 32. Can you confirm that change?

    Regards,

    Raquel.

  • Hi Raquel,

    Thank you for your reply! Below I have provided the buffer declarations. Byte is 00 and the define *_BYTE does equal 0. I apologize for the mistake in my original post. I can confirm the change in the CCD_SIZE. I do not know what other issues could possibly be causing the double sending of bytes. Thank you for your help!

    uint8_t ucSPI1txPrim[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
                               31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,
                               59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
                               87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
                               112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,
                               133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,
                               154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
                               176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
                               198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,
                               220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,
                               242,243,244,245,246,247,248,249,250,251,252,253,254,255 };

    uint8_t ucSPI1txAlt[] = { 1,1,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
                               31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,
                               59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
                               87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
                               112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,
                               133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,
                               154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
                               176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
                               198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,
                               220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,
                               242,243,244,245,246,247,248,249,250,251,252,253,254,255 };
    Regards,
    Cippy
  • Hi Cippy,

    The SPI of the ADuCM362 requires the DMA to do half word access. Can you change the SRC_SIZE and SRC_INC to half word and see if it works?

    Can you confirm if DMACHAN_DSC_ALIGN in DmaLib.h is defined as 0x400?

    In ftp://ftp.analog.com/pub/MicroConverter/ADuCM36x/code there are DMA examples SPI0 and SPI1, they can be a starting point to get the DMA working