SPI Triggered by GPIO

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SPI Triggered by GPIO

1,442 次查看
Asaf
Contributor I

Hi,

my device is MK64FN1m0xxx12.

i try to configue SPI2 triggered by GPIOC pin 15 with SPI2 Rx and Tx DMA.

I configure as follow:

#define ADS1299_SPI_CHANNEL (SPI_CH_2)
#define ADS1299_CONFIGURATION_BAUD (1000000)
#define ADS1299_SAMPLING_BAUD (8000000)
 
#define ADS1299_MAX_BYTE_IN_FRAME (27)
#define ADS1299_MAX_FRAME (64)
#define ADS1299_MAX_BYTE_IN_PACKET (MAX_BYTE_IN_FRAME * MAX_FRAME)
#define ADS1299_MAX_SAMPLE_IN_PACKET (MAX_BYTE_IN_PACKET / 3)
 
#define ADS1299_MAX_PACKET_TCD_POOL (ADS1299_MAX_FRAME)
#define ADS1299_MAX_BYTE_IN_BLOCK (ADS1299_MAX_BYTE_IN_FRAME)
#define ADS1299_MAX_SAMPLE_PACKET (2)
#define ADS1299_MAX_SPI_TCD_POOL (ADS1299_MAX_SAMPLE_PACKET * ADS1299_MAX_PACKET_TCD_POOL)
U8   SampleBlock[2][64 * 27] ;
 
  SPI_CH_2
  edma_handle_t Rx ;
  edma_handle_t Tx ;
  edma_transfer_config_t TxTransferConfig = {0};
  edma_transfer_config_t RxTransferConfig = {0};
  AT_QUICKACCESS_SECTION_DATA_ALIGN( edma_tcd_t Tcd_SpiTxMemoryPool[ADS1299_MAX_SPI_TCD_POOL + 1] , sizeof(edma_tcd_t) );
  AT_QUICKACCESS_SECTION_DATA_ALIGN( edma_tcd_t Tcd_SpiRxMemoryPool[ADS1299_MAX_SPI_TCD_POOL + 1] , sizeof(edma_tcd_t) );
 
//Code //
  DMAMUX_SetSource ( DMAMUX0, 11, kDmaRequestMux0PortC );
  DMAMUX_EnableChannel ( DMAMUX0, 11 );
  EDMA_CreateHandle ( &Tx, DMA0, 11 );
  EDMA_ResetChannel ( DMA0, 11 );
 
  DMAMUX_SetSource ( DMAMUX0, 9, kDmaRequestMux0SPI2 );
  DMAMUX_EnableChannel ( DMAMUX0, 9 );
  EDMA_CreateHandle ( &Rx, DMA0, 9 );
  EDMA_ResetChannel ( DMA0, 9 );
  EDMA_SetCallback ( &Rx, DMACallback, NULL );
 
  U8 NextIndex = 0 ;
  U8 TcdPoolForMemory = ADS1299_MAX_FRAME ; //8 / 2 double buffer
  U8 TcdMemoryPoolIndex = 0 ;
  U8 MemporyPoolIndex = 0 ;
  U8 MemoryForPoolSize = ADS1299_MAX_BYTE_IN_FRAME ;
 
  for( U8 i = 0 ; i < 2 ; i++ ){
if( NextIndex + 1 >= 2 )NextIndex = 0 ;
else NextIndex++ ;
 
EDMA_PrepareTransfer ( pSPITxTransferConfig , SampleBlock + MemoryForPoolSize * i , 1 , &SPI2->PUSHR ,
  1 , 1 , MemoryForPoolSize , kEDMA_MemoryToPeripheral );
EDMA_TcdSetTransferConfig ( &Tcd_SpiTxMemoryPool[i], pSPITxTransferConfig, &Tcd_SpiTxMemoryPool[NextIndex] );
 
    EDMA_PrepareTransfer ( pSPIRxTransferConfig, &SPI2->POPR, 1 , SampleBlock  + MemoryForPoolSize * i ,
      1   , 1, MemoryForPoolSize , kEDMA_PeripheralToMemory );
    EDMA_TcdSetTransferConfig ( &Tcd_SpiRxMemoryPool[i], pSPIRxTransferConfig, &Tcd_SpiRxMemoryPool[NextIndex] );
 
    if( (++TcdMemoryPoolIndex != 0) && !(TcdMemoryPoolIndex % TcdPoolForMemory) ){
      EDMA_TcdEnableInterrupts( &Tcd_SpiRxMemoryPool[i], kEDMA_MajorInterruptEnable ) ;
      TcdMemoryPoolIndex = 0 ;
      MemporyPoolIndex++ ;
    }
  }
 
  EDMA_InstallTCD ( DMA0, 11, &Tcd_SpiTxMemoryPool[0] );
  EDMA_StartTransfer ( &Tx );
  EDMA_InstallTCD ( DMA0, 9, &Tcd_SpiRxMemoryPool[0] );
  EDMA_StartTransfer ( &Rx );
what im doing wrong?
advice
0 项奖励
回复
3 回复数

1,365 次查看
Asaf
Contributor I

I didnt found example of gpio trigger dma that work on k64fn1m0xxx12

i will be glad for real example for gpio trigger dma for spi2

Advice thanks

0 项奖励
回复

1,440 次查看
Asaf
Contributor I

more detiles i get data ready GPIOC pin 15 foling hadge and then i need to read 27 bytes.

i have two buffers each buffer size of 64 * 27

each tcd read 27 bytes i have 64 tcd for each buffer

0 项奖励
回复

1,384 次查看
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hello,

 

I would recommend taking as a base the edma_b2b_transfer SDK example. You can take it as a base, but modify it to meet your requirements.

I apologize, but we do not have an example that fits your requirements. The customization of the example should be done by each customer.

Also, maybe this community post might be helpful: Using the DMA module in Kinetis Devices - NXP Community

 

Regards,

Ricardo

0 项奖励
回复