pic32/libraries/DSPI/DSPI.cpp
/* ------------------------------------------------------------ */
/***	DSPI::begin
**
**	Parameters:
**		pinT		- pin to use for SS instead of the default.
**
**	Return Value:
**		none
**
**	Errors:
**		none
**
**	Description:
**		Initialize the SPI port with the default values. This
**		will set the clock rate to the default speed and the
**		pin for SS to the specified pin.
*/
:begin

pinT            - pin to use for SS instead of the default.

Return Value:
none

none

Initialize the SPI port with the default values. This
will set the clock rate to the default speed and the
pin for SS to the specified pin.
: begin pinT - pin to use for SS instead of the default . Return Value : none none Initialize the SPI port with the default values . This will set the clock rate to the default speed and the pin for SS to the specified pin .
bool DSPI::begin(uint8_t pinT) {
	p32_regset *	    pregIpc;
	int				    bnVec;
	volatile uint8_t    bTmp;   
	uint16_t		    brg;
#if defined(__PIC32_PPS__)
    pinMode(pinMISO, INPUT);
    mapPps(pinMISO, ppsMISO);
    pinMode(pinMOSI, OUTPUT);
    mapPps(pinMOSI, ppsMOSI);
#endif
    setIntVector(vec, isr);
	setPinSelect(pinT);
	pregIec->clr = bitErr + bitRx + bitTx;
	pspi->sxCon.reg = 0;
	bTmp = pspi->sxBuf.reg;
    (void) bTmp;    
	pregIfs->clr = bitErr + bitRx + bitTx;
	pregIpc = ((p32_regset *)&IPC0) + (vec / 4);	
	bnVec = 8 * (vec % 4);
	pregIpc->clr = (0x1F << bnVec);
	pregIpc->set = ipl << bnVec;
	brg = (uint16_t)((__PIC32_pbClk / (2 * _DSPI_SPD_DEFAULT)) - 1);
	pspi->sxBrg.reg = brg;
	pspi->sxStat.clr = (1 << _SPISTAT_SPIROV);
	fRov = 0;
	pspi->sxCon.reg = 0;
	pspi->sxCon.set = (1 << _SPICON_ON) + (1 << _SPICON_MSTEN) + DSPI_MODE0;
    return(true);
}
bool DSPI :: begin ( uint8_t pinT ) { p32_regset * pregIpc ; int bnVec ; volatile uint8_t bTmp ; uint16_t brg ; #if defined ( __PIC32_PPS__ ) pinMode ( pinMISO , INPUT ) ; mapPps ( pinMISO , ppsMISO ) ; pinMode ( pinMOSI , OUTPUT ) ; mapPps ( pinMOSI , ppsMOSI ) ; #endif setIntVector ( vec , isr ) ; setPinSelect ( pinT ) ; pregIec -> clr = bitErr + bitRx + bitTx ; pspi -> sxCon . reg = 0 ; bTmp = pspi -> sxBuf . reg ; ( void ) bTmp ; pregIfs -> clr = bitErr + bitRx + bitTx ; pregIpc = ( ( p32_regset * ) & IPC0 ) + ( vec / 4 ) ; bnVec = 8 * ( vec % 4 ) ; pregIpc -> clr = ( 0x1F << bnVec ) ; pregIpc -> set = ipl << bnVec ; brg = ( uint16_t ) ( ( __PIC32_pbClk / ( 2 * _DSPI_SPD_DEFAULT ) ) - 1 ) ; pspi -> sxBrg . reg = brg ; pspi -> sxStat . clr = ( 1 << _SPISTAT_SPIROV ) ; fRov = 0 ; pspi -> sxCon . reg = 0 ; pspi -> sxCon . set = ( 1 << _SPICON_ON ) + ( 1 << _SPICON_MSTEN ) + DSPI_MODE0 ; return ( true ) ; }
DSPI::begin
DSPI :: begin
// volatile to make sure optimizer does not remove instruction /* Map the SPI MISO to the appropriate pin.  Some chips need the
       pins to be set to the right mode, either for the IO functionality
       or to disable any analog on the pin.
	*/ /* Map the SPI MOSI to the appropriate pin.
	*/ // set up the interrupt handler  /* Initialize the pins. The pin directions for SDO, SDI and SCK
	** are set automatically when the SPI controller is enabled. The
	** SS pin isn't explicitly used by the SPI controller when in
	** master mode, so we need to initialize it ourselves.
	*/ /* Disable interrupts on this SPI controller.
	*/ /* Disable and reset the SPI controller.
	*/ /* Clear the receive buffer.
	*/ // suppress unused variable complier warning /* Clear all SPI interrupt flags.
	*/ /* Compute the address of the interrupt priority control register
	** used by this SPI controller.
	*/ // interrupt priority control register /* Compute the bit position of the interrupt priority bits for
	** this interrupt vector.
	*/ /* Set the interrupt priority and sub-priority bits.
	** The interrupt priorty control register address and the priority bits
	** can be computed from the vector number. Each IPC register contains the
	** the priority bits for four vectors. Each byte of an IPC registger contains
	** the priority and sub-priority bits arranged such that  bits 0-1 are
	** the sub-priority, bits 2-4 the priority, and bits 5-7 unused.
	*/ /* Set the default baud rate.
	*/ /* Clear the receive overflow bit and receive overflow error flag
	*/ /* Enable the SPI controller.
	** Warning: if the SS pin ever becomes a LOW INPUT then SPI 
	** automatically switches to Slave, so the data direction of 
	** the SS pin MUST be kept as OUTPUT.
	*/