SAM4L - SPI through PDCA (DMA)

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

honzek68
Posts: 5
Joined: Wed Nov 26, 2014 7:01 pm

SAM4L - SPI through PDCA (DMA)

Wed Nov 26, 2014 7:11 pm

Dears,
 
I have Atmel studio 6.2 using ASF library, I want to use SPI through DMA. I have external device which has the FIFO and I want to read the all FIFO with SPI but not byte by byte, but by DMA. My MCU is master. 
1) I want to enable DMA for start reading FIFO by DMA
2) After read all the FIFO - Dma transfer is done => interrupt handler
3) In interrupt handler I st global flag for DATA_FROM_FIFO=DONE;
 Can yo help me?
 
Here is Setting of DMA

Code: Select all




#define PDCA_SPI_CHANNEL_RX  2
#define PDCA_SPI_LINE_RX    4	//from peripheral to memory = SPI RX
#define PDCA_SPI_LENGTH   sizeof(GP_GGA)
volatile char Spi_data[PDCA_SPI_LENGTH];




#define PDCA_SPI_CHANNEL_TX  3
#define PDCA_SPI_LINE_TX    22	//from mem to peripheral = SPI TX
volatile char Dummy_data[PDCA_SPI_LENGTH];




/** PDCA channel options. */
pdca_channel_config_t PDCA_SPI_RX = {
	.addr = (void *)Spi_data, /* memory address */
	.pid = PDCA_SPI_LINE_RX, /* select peripheral - USART1 RX line.*/
	.size =PDCA_SPI_LENGTH, /* transfer counter */
	.r_addr = 0, /* next memory address */
	.r_size = 0, /* next transfer counter */
	.transfer_size = PDCA_MR_SIZE_BYTE, /* select size of the transfer */
	.etrig = false, /* disable event trigger*/
	.ring = false /* not use ring buffer*/
};




/** PDCA channel options. */
pdca_channel_config_t PDCA_SPI_TX = {
	.addr = (void *)Dummy_data, /* memory address */
	.pid = PDCA_SPI_LINE_TX, /* select peripheral - USART1 RX line.*/
	.size =PDCA_SPI_LENGTH, /* transfer counter */
	.r_addr = 0, /* next memory address */
	.r_size = 0, /* next transfer counter */
	.transfer_size = PDCA_MR_SIZE_BYTE, /* select size of the transfer */
	.etrig = false, /* disable event trigger*/
	.ring = false /* not use ring buffer*/
};




void Dma_SPI_init(void)
{
	//PDCA SPI http://simplemachines.it/martin/mizar32/1.6.0-AT32UC3/COMPONENTS/MEMORY/SD_MMC/SD_MMC_SPI/EXAMPLE/DOC/html/a00006.html
	//http://www.avrfreaks.net/forum/pdca-spi
	pdca_enable(PDCA);	//Enable clock for PDCA - DMA
	
	pdca_channel_set_config(PDCA_SPI_CHANNEL_RX , &PDCA_SPI_RX);
	pdca_channel_set_config(PDCA_SPI_CHANNEL_TX , & PDCA_SPI_TX);
	pdca_channel_set_callback(PDCA_SPI_CHANNEL_RX , PDCA_SPI_Done,PDCA_SPI_LINE_RX, 3, PDCA_IER_TRC);	//Transefer completet IRQ
	
	
	NVIC_EnableIRQ(SPI_IRQn);
}
NOW I set the transfer for reading the FIFO

Code: Select all

start read FIFO from adress 0
	//sekect device
	spi_select_device(SPI, &device);
	//send pointer to device - whch adress start to read
	spi_put(SPI, 0 & 0x7F);
			
	//Enable PDCA for read data from Fifo in Semtech
	pdca_channel_enable_interrupt(PDCA_SPI_CHANNEL_RX,PDCA_IER_TRC);
	/* Load PDCA */
	pdca_channel_write_load(PDCA_SPI_CHANNEL_RX,(void *)Spi_data,PDCA_SPI_LENGTH);
	/* Enable the PDCA Rx channel first then the Tx channel */
	pdca_channel_enable(PDCA_SPI_CHANNEL_RX);				
	
	/* Send dummy data from Semtech */
	pdca_channel_write_load(PDCA_SPI_CHANNEL_TX,(void *)Dummy_data,PDCA_SPI_LENGTH);
	pdca_channel_enable(PDCA_SPI_CHANNEL_TX);
	
	//wait until the FIFO data are read
	xSemaphoreTake(RX_Data_RF,portMAX_DELAY);
Here is Interrupt for Transfer is done

Code: Select all

static void PDCA_SPI_Done(enum pdca_channel_status status)
{
	if (status == PDCA_CH_TRANSFER_COMPLETED)
	{
		pdca_channel_disable(PDCA_SPI_CHANNEL_RX);
		pdca_channel_disable_interrupt (PDCA_SPI_CHANNEL_RX,PDCA_IER_TRC);
		
		xSemaphoreGiveFromISR(RX_Data_RF,pdTRUE);
		
		
	}
	
}
It does not work, no interrupt occurs. Probably no data are transfer or read through SPI. If I use classical SPI - Everething works, but I do not want to read without DMA => I Want to use DMA
pholt
Posts: 1
Joined: Mon Jun 08, 2015 12:29 pm

Re: SAM4L - SPI through PDCA (DMA)

Mon Jun 08, 2015 12:33 pm

Hi,
I have exactly the same problem, did you find a solution?

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest