Beispiel #1
0
/*****************************************************************************
  Function:
    void WF_SpiInit(void)

  Summary:
    Initializes the SPI interface to the MRF24W device.

  Description:
    Configures the SPI interface for communications with the MRF24W.

  Precondition:
    None

  Parameters:
    None

  Returns:
    None

  Remarks:
    This function is called by WFHardwareInit.
*****************************************************************************/
void WF_SpiInit(void)
{
    /* disable the spi interrupt */
    #if defined( __XC32 )
        WF_SPI_IE_CLEAR = WF_SPI_INT_BITS;
    #else
        WF_SPI_IE = 0;
    #endif
    #if defined( __XC8)
        WF_SPI_IP = 0;
    #endif

    // Set up the SPI module on the PIC for communications with the MRF24W
    WF_CS_IO       = 1;
    WF_CS_TRIS     = 0;     // Drive SPI MRF24W chip select pin
    #if defined( __XC8)
        WF_SCK_TRIS    = 0;     /* SPI Clock is an output       */
        WF_SDO_TRIS    = 0;     /* SPI Data Out is an output    */
        WF_SDI_TRIS    = 1;     /* SPI Data In is an input      */
    #else
        // We'll let the module control the pins.
    #endif

    #if !defined( SPI_IS_SHARED )
    ConfigureSpiMRF24W();
    #endif

    /* clear the completion flag */
    ClearSPIDoneFlag();
}
Beispiel #2
0
/*****************************************************************************
  Function:
    bool WF_SpiInit(void)

  Summary:
    Initializes the SPI interface to the MRF24W device.

  Description:
    Configures the SPI interface for communications with the MRF24W.

  Precondition:
    None

  Parameters:
    None

  Returns:
    None
      
  Remarks:
    This function is called by WFHardwareInit.
*****************************************************************************/
bool WF_SpiInit(void)
{
    bool res;
    
    /* disable the spi interrupt if necessary */
    // No need because SPI interrupt is not used

    // Initialize IO for WF chip select    
    WF_CS_Init();     
    WF_SpiDisableChipSelect();  // Disable chip select before initialization

    res = ConfigureSpiMRF24W();  
    return res;
}
Beispiel #3
0
/*****************************************************************************
  Function:
    void WF_SpiEnableChipSelect(void)

  Summary:
    Enables the MRF24W SPI chip select.

  Description:
    Enables the MRF24W SPI chip select as part of the sequence of SPI
    communications.

  Precondition:
    None

  Parameters:
    None

  Returns:
    None

  Remarks:
    If the SPI bus is shared with other peripherals then the current SPI context
    is saved.
*****************************************************************************/
void WF_SpiEnableChipSelect(void)
{
    #if defined(__XC8)
    static volatile uint8_t dummy;
    #endif

    #if defined(SPI_IS_SHARED)
    SaveSpiContext();
    ConfigureSpiMRF24W();
    #endif

    /* set Slave Select low (enable SPI chip select on MRF24W) */
    WF_CS_IO = 0;

    /* clear any pending interrupts */
    #if defined(__XC8)
        dummy = WF_SSPBUF;
        ClearSPIDoneFlag();
    #endif


}