lpcware

SSP0 + DMA

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Lobisomem on Thu Feb 27 12:13:37 MST 2014
Hi all !!

Please, take a look at the following code:

void DMA_IRQHandler(void)
{
__asm volatile("nop"::);
}
//-----------------------------------------------------------------------------

void spi_init()
{
//---------------------------
//-  P1.20 -> shift CLK     -
//---------------------------
// Put pin as third alternate func
PINSEL3  |= (0x03 << 8);
// Put the pull up resistor
PINMODE3 &= ~(0x03 << 8);
//---------------------------
//-  P1.23 ->   MISO        -
//---------------------------
// Put pin as third alternate func
PINSEL3  |= (0x03 << 14);
// Put the pull up resistor
    PINMODE3 &= ~(0x03 << 14);
//---------------------------
//-  P1.24 ->  MOSI         -
//---------------------------
// Put pin as third alternate func
PINSEL3  |= (0x03 << 16);
// Put the pull up resistor
PINMODE3 &= ~(0x03 << 16);

// ----------------------------------
// --------     SSP0      -----------
// ----------------------------------

// Turn on the SSP0 clock
PCONP |= (1 << 21);

// Select the peripheral clock
// Put SSP0 feed clock = (System clock / 1)
PCLKSEL1 &= ~(0x03 << 10);
PCLKSEL1 |=  (0x01 << 10);

// Put 16 bits data transfer
// Pre-scaler = 0
LPC_SSP0->CR0 = 0x00Cf;

// Enable the controller
LPC_SSP0->CR1 |= (1 << 1);

// Set the pre scaler
LPC_SSP0->CPSR = 8;

// Enable the RX FIFO to generate DMA request
LPC_SSP0->DMACR = 0x1;
}
//-----------------------------------------------------------------------------

void dma_init(void)
{
// Turn DMA on
PCONP |= (1 << 29);

// Enable the DMA
LPC_GPDMA->DMACConfig = 1;
while ( !(LPC_GPDMA->DMACConfig & 0x01) );

// Clear any pending interrupt
LPC_GPDMA->DMACIntTCClear = 1;

    // Enable the interrupt on NVIC
NVIC_EnableIRQ(DMA_IRQn);

// Set source address
LPC_GPDMACH0->DMACCSrcAddr  = (uint32_t)&LPC_SSP0->DR;

// Set the destination address
LPC_GPDMACH0->DMACCDestAddr = (uint32_t)dmaBuffer;

// No linked list
LPC_GPDMACH0->DMACCLLI      = 0;

// Set the length of the transfer
// Make destination auto increment
// Enable the terminal count interrupt
LPC_GPDMACH0->DMACCControl = 1 | (1<<27) | (1<<31);

// Select SSP0 RX DMA request
LPC_GPDMACH0->DMACCConfig = (1<<1);
// Peripheral to memory transfer
LPC_GPDMACH0->DMACCConfig |= (2<<11);
// Set error interrupt
LPC_GPDMACH0->DMACCConfig |= (1<<14);
// Set terminal count interrupt
LPC_GPDMACH0->DMACCConfig |= (1<<15);
// Turn Channel 0 on
LPC_GPDMACH0->DMACCConfig |= 1;
}
//-----------------------------------------------------------------------------


int main(void)
{
//system_setSysTicTimerTo1ms();
    spi_init();
    dma_init();

    // Write to data reg to generate clock
    LPC_SSP0->DR = 0x00;

    while(1) {

    }
    return 0 ;
}


Well, as one may observ, I am trying to get a byte from an off-chip ADC conected to the SSP0. And I am trying to make the transfer tho memory by DMA. The thing is ... it is not working ! The DMA never generates the interrupt. Can you help me and show me what I am doing wrong ?

Best regards

Outcomes