
UM10800
All information provided in this document is subject to legal disclaimers.
© NXP Semiconductors N.V. 2016. All rights reserved.
User manual
Rev. 1.2 — 5 October 2016
413 of 487
NXP Semiconductors
UM10800
Chapter 28: LPC82x SPI API ROM driver routines
// Enable DMA for SPI RX first. For RX only or TX_RX, only callback_rxd is
// needed.
if (driver->callback_rxd != NULL) {
chn.callback_func_pt = driver->callback_rxd; //set callback function
}
tsk.ch_num = dma_cfg->dma_rxd_num;
tsk.data_type = DMA_8_BIT | DMA_DST_INC_1;
// peripheral to memory
tsk.src = (uint32_t)&lspi->RXDAT;
tsk.dst = (uint32_t)driver->buff tsk.data_length;
tsk.task_addr = NULL; // for task head, no momery is needed.
error_code = pDmaApi->dma_init((DMA_HANDLE_T*)dma_cfg->dma_handle, &chn,
&tsk);
if ( error_code != LPC_OK )
return ( error_code );
tsk.ch_num = dma_cfg->dma_txd_num;
tsk.data_type = DMA_8_BIT | DMA_SRC_INC_1;
// memory to peripheral
tsk.src = (uint32_t)driver->buff tsk.data_length;
tsk.dst = (uint32_t)&lspi->TXDAT;
tsk.task_addr = NULL; // for task head, no momery is needed.
error_code = pDmaApi->dma_init((DMA_HANDLE_T*)dma_cfg->dma_handle, &chn,
&tsk);
return( error_code ); //init spi dma channel
}
11. Define the receive callback function. This function is called when the DMA transfer
has finished and sets the EOT bit to one in the SP TXDATCTL register (see
) to set the SSEL signal to HIGH.
void receive_callback( uint32_t err_code, uint32_t n ) {
LSPI_REGS_T *lspi = ((LSPI_REGS_T
*)((SPI_DRIVER_TypeDef*)spi_handle)->base_addr);
if (err_code != LPC_OK)
while(1);
// set the EOT flag in the TXCTL register
if ( lspi->CFG & CFG_MASTER )
lspi->TXCTL |= TXDATCTL_EOT;
receive_tag = 1;
}
12. DMA transmits data. Slave sends some data back to the DMA.
receive_tag = 0;
pSpiApi->spi_master_transfer(spi_handle, ¶m);
while(!receivetag); //wait for receive tag to be set