コード例 #1
0
// *****************************************************************************
// @fn          spi_init
// @brief       Initialize SPI
// @param       none
// @return      none
// *****************************************************************************
void spi_init(void)
{
    setupCmu();
    setupSpi();
#ifdef SPI_USE_DMA
    setupDma();
#endif
    DPRINT("SPI Init.");
}
コード例 #2
0
/**************************************************************************//**
 * @brief  Main function
 * Main is called from __iar_program_start, see assembly startup file
 *****************************************************************************/
int main(void)
{ 
  /* Initialize chip */
  CHIP_Init();
  
  /* Configuring clocks in the Clock Management Unit (CMU) */
  setupCmu();
  
  /* Configure DMA scatter-gather transfer */      
  configureDmaTransfer();
  
  /* Starting the scatter-gather DMA operation */
  DMA_ActivateScatterGather(DMA_CHANNEL_SCATTERGATHER,
                            false,
                            &dmaScatterCfgBlock[0],
                            SCATTER_GATHER_TRANSFERS);
  
  /* Enter EM1 while DMA transfer is active to save power. Note that
   * interrupts are disabled to prevent the ISR from being triggered
   * after checking the transferActive flag, but before entering
   * sleep. If this were to happen, there would be no interrupt to wake
   * the core again and the MCU would be stuck in EM1. While the 
   * core is in sleep, pending interrupts will still wake up the 
   * core and the ISR will be triggered after interrupts are enabled
   * again. 
   */
  while(1)
  {
    INT_Disable();
    if ( transferActive )
    {
      EMU_EnterEM1(); 
    }
    INT_Enable();
    
    /* Exit the loop if transfer has completed */
    if ( !transferActive )
    {
      break;
    }
  }
 
  /* Cleaning up after DMA transfers */
  DMA_Reset();

  /* Done */
  while (1);
}
コード例 #3
0
ファイル: adc_basic.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 * This exmaple sets up the TIMER to trigger the ADC through PRS at a set
 * interval. The ADC then sets a DMA request and the DMA fetches each sample
 * until the a set number of samples have been received. 
 *****************************************************************************/
int main(void)
{ 
  /* Initialize chip */
  CHIP_Init();
  
  /* Configuring clocks in the Clock Management Unit (CMU) */
  setupCmu();
  
  /* Configure DMA transfer from ADC to RAM */      
  setupDma();
  
  /* Configure ADC Sampling and TIMER trigger through PRS. Start TIMER as well */
  setupAdc();
  
  /* Enter EM1 while DMA transfer is active to save power. Note that
   * interrupts are disabled to prevent the ISR from being triggered
   * after checking the transferActive flag, but before entering
   * sleep. If this were to happen, there would be no interrupt to wake
   * the core again and the MCU would be stuck in EM1. While the 
   * core is in sleep, pending interrupts will still wake up the 
   * core and the ISR will be triggered after interrupts are enabled
   * again. 
   */
  while(1)
  {
    INT_Disable();
    if ( transferActive )
    {
      EMU_EnterEM1(); 
    }
    INT_Enable();
    
    /* Exit the loop if transfer has completed */
    if ( !transferActive )
    {
      break;
    }
  }
 
  /* Cleaning up after DMA transfers */
  DMA_Reset();

  /* Done */
  while (1);
}
コード例 #4
0
/**************************************************************************//**
 * @brief  Main function
 * This example sets up the DMA to transfer outbound and incoming data from the
 * SPI (USART1) to/from the source/destination buffers. Three tests are done:
 * 1) Transmit data (string) without reading received data
 * 2) Transmit data (string) and transfer received data to RAM buffer
 * 3) Transmit dummy data and transfer received data to RAM buffer
 *****************************************************************************/
int main(void)
{ 
  /* Initialize chip */
  CHIP_Init();
  
  /* Configuring clocks in the Clock Management Unit (CMU) */
  setupCmu();
  
  /* Configura USART for SPI */
  setupSpi();
    
  /* Configure DMA transfer from RAM to SPI using ping-pong */      
  setupDma();
  
  /* Send data to slave, no data reception */
  spiDmaTransfer((uint8_t*) spiTxData, NULL, SPI_TRANSFER_SIZE);
  
  /* Sleep until transfer is done */
  sleepUntilTransferDone();
  
  /* Send data to slave and save received data in buffer */
  spiDmaTransfer((uint8_t*) spiTxData, (uint8_t*) spiRxData1, SPI_TRANSFER_SIZE);
  
  /* Sleep until transfer is done */
  sleepUntilTransferDone();
  
  /* Send dummy data to slave and save received data in buffer */
  spiDmaTransfer(NULL, (uint8_t*) spiRxData2, SPI_TRANSFER_SIZE);

  /* Sleep until transfer is done */
  sleepUntilTransferDone();
  
  /* Send dummy data to slave and save received data in buffer */
  spiDmaTransfer(NULL, (uint8_t*) spiRxData2, SPI_TRANSFER_SIZE);

  /* Sleep until transfer is done */
  sleepUntilTransferDone();
  
  /* Send data to slave, no data reception */
  spiDmaTransfer((uint8_t*) spiTxData, NULL, SPI_TRANSFER_SIZE);
  
  /* Sleep until transfer is done */
  sleepUntilTransferDone();
  
  /* Send data to slave and save received data in buffer */
  spiDmaTransfer((uint8_t*) spiTxData, (uint8_t*) spiRxData1, SPI_TRANSFER_SIZE);
  
  /* Sleep until transfer is done */
  sleepUntilTransferDone();
  
  /* Send dummy data to slave and save received data in buffer */
  spiDmaTransfer(NULL, (uint8_t*) spiRxData2, SPI_TRANSFER_SIZE);

  /* Sleep until transfer is done */
  sleepUntilTransferDone();
 
  /* Cleaning up after DMA transfers */
  DMA_Reset();

  /* Done */
  while (1);
}