AnsweredAssumed Answered

SPI slave mode with DMA not working

Question asked by janhieber on Jul 19, 2016
Latest reply on Jul 19, 2016 by janhieber

Hi,

I'm using the 21479 EZKit for development with CCES.

 

I have some audio processing implemented and now want to receive filter parameters via SPI.

So the DSP is slave, and an STM32 is master. I have set up everything (I think correct), but it's not working and I don't know where to look for the problem.

I want to receive data in 8-bit mode via DMA, firing an interrupt when 3 bytes were received.

 

First the SRU code:

SRU(DPI_PB11_O, SPIB_MOSI_I);

SRU(SPIB_MISO_O, DPI_PB12_I);

SRU(DPI_PB13_O, SPIB_CLK_I);

SRU(DPI_PB14_O, SPIB_DS_I);

SRU(SPIB_MOSI_PBEN_O, DPI_PBEN11_I);

SRU(SPIB_MISO_PBEN_O, DPI_PBEN12_I);

SRU(SPIB_CLK_PBEN_O, DPI_PBEN13_I);

SRU(LOW, DPI_PBEN14_I);

 

Then the SPI setup:

// this is for the received data, DMA
char spibuf[10];

 

// interrupt handler

static void spi_isr(uint32_t iid, void *handlerarg){

    // print received data

    printf_("received: 0x%02x 0x%02x 0x%02x", spibuf[0], spibuf[1], spibuf[2]);

    // clear buffer

    for(int i=0; i<sizeof(spibuf); i++)

        spibuf[i] = 0;

}

 

// setup, is called from main()

void init_SPIB(void) {

    // clear registers, set RX/TX flush bits

    *pSPICTLB = (TXFLSH | RXFLSH);

    *pSPIDMACB = FIFOFLSH;

    *pSPIFLGB = 0;

    *pSPIBAUDB = 0;

    *pSPISTATB = 0xff;

 

    // config DMA

    *pIISPIB = (unsigned int)spibuf;

    *pIMSPIB = 1;

    *pCSPIB = 2;

 

    // clear receive buffer

    for(int i=0; i<sizeof(spibuf); i++)

        spibuf[i] = 0;

 

    // setup and enable SPI

    *pSPICTLB = (WL8 | SENDZ | TIMOD2 | CPHASE | CLKPL | MSBF);

    *pSPICTLB |= SPIEN;

 

    // setup and enable DMA

    *pSPIDMACB = (INTEN | SPIRCV);

    *pSPIDMACB |= SPIDEN;

 

    // install interrupt handler

    adi_int_InstallHandler(ADI_CID_P18I, spi_isr, 0, true);

}

 

I read enough forum posts here with example code to be relative sure that this is correct.

But when I flash it, the interrupt fires only once and spibuf contains not the data I sent from the STM32.

So even with the wrong data the interrupt should fire again when more data is received.

 

SPI on STM32 is configured with this settings:
1,3125 MBits/s, 8bit data, MSB first, CPOL low, CPHA 1 edge

I tried pulling slave select low, transfer 3 bytes, pull slave select high.

I also tried setting slave select HIGH between each byte.

 

I also don't know how the transmitting of data works in slave mode with DMA.

Would be nice if someone could help me

 

best regards

Jan

Outcomes