Ejemplo n.º 1
0
/*******************************************************************************
* Function Name: SPIM_Init
********************************************************************************
*
* Summary:
*  Inits/Restores default SPIM configuration provided with customizer.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Side Effects:
*  When this function is called it initializes all of the necessary parameters
*  for execution. i.e. setting the initial interrupt mask, configuring the 
*  interrupt service routine, configuring the bit-counter parameters and 
*  clearing the FIFO and Status Register.
*
* Reentrant:
*  No.
*
*******************************************************************************/
void SPIM_Init(void)
{    
    /* Initialize the Bit counter */
    SPIM_COUNTER_PERIOD_REG = SPIM_BITCTR_INIT;
    
    /* ISR initialization  */  
    #if(SPIM_InternalTxInterruptEnabled)
    
        CyIntDisable(SPIM_TX_ISR_NUMBER);

        /* Set the ISR to point to the SPIM_isr Interrupt. */
        CyIntSetVector(SPIM_TX_ISR_NUMBER, SPIM_TX_ISR);

        /* Set the priority. */
        CyIntSetPriority(SPIM_TX_ISR_NUMBER, SPIM_TX_ISR_PRIORITY);
        
    #endif /* SPIM_InternalTxInterruptEnabled */                                
    
    #if(SPIM_InternalRxInterruptEnabled)
    
        CyIntDisable(SPIM_RX_ISR_NUMBER);

        /* Set the ISR to point to the SPIM_isr Interrupt. */
        CyIntSetVector(SPIM_RX_ISR_NUMBER, SPIM_RX_ISR);

        /* Set the priority. */
        CyIntSetPriority(SPIM_RX_ISR_NUMBER, SPIM_RX_ISR_PRIORITY);
        
    #endif /* SPIM_InternalRxInterruptEnabled */
    
    /* Clear any stray data from the RX and TX FIFO */    
	SPIM_ClearFIFO();
	
	#if(SPIM_RXBUFFERSIZE > 4u)
    
        SPIM_rxBufferRead = 0u;
        SPIM_rxBufferWrite = 0u;

    #endif /* SPIM_RXBUFFERSIZE > 4u */
	
    #if(SPIM_TXBUFFERSIZE > 4u)
    
        SPIM_txBufferRead = 0u;
        SPIM_txBufferWrite = 0u;

    #endif /* SPIM_TXBUFFERSIZE > 4u */
    
    (void) SPIM_ReadTxStatus(); /* Clear any pending status bits */
    (void) SPIM_ReadRxStatus(); /* Clear any pending status bits */
	
	/* Configure the Initial interrupt mask */
    #if (SPIM_TXBUFFERSIZE > 4u)
        SPIM_TX_STATUS_MASK_REG  = SPIM_TX_INIT_INTERRUPTS_MASK & 
                                                ~SPIM_STS_TX_FIFO_NOT_FULL;                    
	#else /* SPIM_TXBUFFERSIZE < 4u */    
        SPIM_TX_STATUS_MASK_REG  = SPIM_TX_INIT_INTERRUPTS_MASK;       
	#endif /* SPIM_TXBUFFERSIZE > 4u */
    
    SPIM_RX_STATUS_MASK_REG  = SPIM_RX_INIT_INTERRUPTS_MASK; 
}
Ejemplo n.º 2
0
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*  Main function performs following functions:
*   1. Starts Character LCD and print project info
*   2. Starts SPI Master component
*   3. Configures the DMA transfer for RX and TX directions
*   4. Displays the results on Character LCD
*   
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
void main()
{
    uint8 i = 0u;
    CyGlobalIntEnable; 
    
    for(i=0u; i<8u; i++)
    {
        m_rxBuffer[i] = 0u;
    }
    
    LCD_Start();
    LCD_Position(0u,0u);
    LCD_PrintString("SPI Master");
    LCD_Position(1u,0u);
    LCD_PrintString("example");
    CyDelay(3000u);
    
    Dma_M_Tx_Configuration();
    Dma_M_Rx_Configuration();
    
    CyDmaChEnable(M_TxChannel, 1u); 
    CyDmaChEnable(M_RxChannel, 1u);
    
    LCD_Position(0u,0u);
    LCD_PrintString("Master Tx data:");
    LCD_Position(1u,0u);
    for(i=0u; i<8u; i++)
    {
        LCD_PrintHexUint8(m_txBuffer[i]);
    }
    
    CyDelay(5000u);
    SPIM_Start();
    
    while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE));
    
    LCD_ClearDisplay();
    LCD_PrintString("Master Rx data:");
    LCD_Position(1u,0u);
    
    for(i=0u; i<8u; i++)
    {
        LCD_PrintHexUint8(m_rxBuffer[i]);
    }
    CyDelay(5000u);
    LCD_ClearDisplay();
    LCD_PrintString("SPI Master");
    LCD_Position(1u,0u);
    LCD_PrintString("example complete.");
     
    for(;;)
    {
        
    }
}
Ejemplo n.º 3
0
/*******************************************************************************
* Function Name: SPIM_Init
********************************************************************************
*
* Summary:
*  Inits/Restores default SPIM configuration provided with customizer.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Side Effects:
*  When this function is called it initializes all of the necessary parameters
*  for execution. i.e. setting the initial interrupt mask, configuring the
*  interrupt service routine, configuring the bit-counter parameters and
*  clearing the FIFO and Status Register.
*
* Reentrant:
*  No.
*
*******************************************************************************/
void SPIM_Init(void) 
{
    /* Initialize the Bit counter */
    SPIM_COUNTER_PERIOD_REG = SPIM_BITCTR_INIT;

    /* Init TX ISR  */
    #if(0u != SPIM_INTERNAL_TX_INT_ENABLED)
        CyIntDisable         (SPIM_TX_ISR_NUMBER);
        CyIntSetPriority     (SPIM_TX_ISR_NUMBER,  SPIM_TX_ISR_PRIORITY);
        (void) CyIntSetVector(SPIM_TX_ISR_NUMBER, &SPIM_TX_ISR);
    #endif /* (0u != SPIM_INTERNAL_TX_INT_ENABLED) */

    /* Init RX ISR  */
    #if(0u != SPIM_INTERNAL_RX_INT_ENABLED)
        CyIntDisable         (SPIM_RX_ISR_NUMBER);
        CyIntSetPriority     (SPIM_RX_ISR_NUMBER,  SPIM_RX_ISR_PRIORITY);
        (void) CyIntSetVector(SPIM_RX_ISR_NUMBER, &SPIM_RX_ISR);
    #endif /* (0u != SPIM_INTERNAL_RX_INT_ENABLED) */

    /* Clear any stray data from the RX and TX FIFO */
    SPIM_ClearFIFO();

    #if(SPIM_RX_SOFTWARE_BUF_ENABLED)
        SPIM_rxBufferFull  = 0u;
        SPIM_rxBufferRead  = 0u;
        SPIM_rxBufferWrite = 0u;
    #endif /* (SPIM_RX_SOFTWARE_BUF_ENABLED) */

    #if(SPIM_TX_SOFTWARE_BUF_ENABLED)
        SPIM_txBufferFull  = 0u;
        SPIM_txBufferRead  = 0u;
        SPIM_txBufferWrite = 0u;
    #endif /* (SPIM_TX_SOFTWARE_BUF_ENABLED) */

    (void) SPIM_ReadTxStatus(); /* Clear Tx status and swStatusTx */
    (void) SPIM_ReadRxStatus(); /* Clear Rx status and swStatusRx */

    /* Configure TX and RX interrupt mask */
    SPIM_TX_STATUS_MASK_REG = SPIM_TX_INIT_INTERRUPTS_MASK;
    SPIM_RX_STATUS_MASK_REG = SPIM_RX_INIT_INTERRUPTS_MASK;
}
Ejemplo n.º 4
0
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*  Main function performs following functions:
*   1. Starts Character LCD and print project info
*   2. Starts SPI Master component
*   3. Configures the DMA transfer for RX and TX directions
*   4. Displays the results on Character LCD
*   
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
int main()
{
    uint8 i;
    
    LCD_Start();
    LCD_Position(0u,0u);
    LCD_PrintString("SPI Master");
    LCD_Position(1u,0u);
    LCD_PrintString("example");
    CyDelay(2000u);
    
    DmaTxConfiguration();
    DmaRxConfiguration();
    
    SPIM_Start();
    
    CyDmaChEnable(rxChannel, STORE_TD_CFG_ONCMPLT);
    CyDmaChEnable(txChannel, STORE_TD_CFG_ONCMPLT);

    while (0u == (SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE))
    {
    }
    
    LCD_ClearDisplay();
    LCD_PrintString("Master Rx data:");
    LCD_Position(1u,0u);
    
    for(i=0u; i<BUFFER_SIZE; i++)
    {
        LCD_PrintHexUint8(rxBuffer[i]);
    }

    for(;;)
    {
    }
}