pic32/libraries/DSPI/DSPI.cpp
/* ------------------------------------------------------------ */
/***	DSPI::setSpeed
**
**	Parameters:
**		spd		- clock speed to set in HZ
**
**	Return Value:
**		none
**
**	Errors:
**		none
**
**	Description:
**		This sets the SPI clock speed to the highest supported
**		frequency that doesn't exceed the requested value. It computes
**		the appropriate value to load into the SPI baud register
**		based on requested clock speed and peripheral bus frequency.
*/
:setSpeed

spd             - clock speed to set in HZ

Return Value:
none

none

This sets the SPI clock speed to the highest supported
frequency that doesn't exceed the requested value. It computes
the appropriate value to load into the SPI baud register
based on requested clock speed and peripheral bus frequency.
: setSpeed spd - clock speed to set in HZ Return Value : none none This sets the SPI clock speed to the highest supported frequency that doesn ' t exceed the requested value . It computes the appropriate value to load into the SPI baud register based on requested clock speed and peripheral bus frequency .
void
DSPI::setSpeed(uint32_t spd) {
	uint16_t	brg;
	brg = (uint16_t)((__PIC32_pbClk / (2 * spd)) - 1);
	if (brg == 0xFFFF) {
		brg = 0;
	}
	if (brg > 0x1FF) {
		brg = 0x1FF;
	}
	pspi->sxCon.clr = (1 << _SPICON_ON);	
    storedBrg = pspi->sxBrg.reg;
	pspi->sxBrg.reg = brg;
	pspi->sxCon.set = (1 << _SPICON_ON);	
}
void DSPI :: setSpeed ( uint32_t spd ) { uint16_t brg ; brg = ( uint16_t ) ( ( __PIC32_pbClk / ( 2 * spd ) ) - 1 ) ; if ( brg == 0xFFFF ) { brg = 0 ; } if ( brg > 0x1FF ) { brg = 0x1FF ; } pspi -> sxCon . clr = ( 1 << _SPICON_ON ) ; storedBrg = pspi -> sxBrg . reg ; pspi -> sxBrg . reg = brg ; pspi -> sxCon . set = ( 1 << _SPICON_ON ) ; }
DSPI::setSpeed
DSPI :: setSpeed
/* Compute the baud rate divider for this frequency.
	*/ /* That the baud rate value is in the correct range.
	*/ /* The user tried to set a frequency that is too high to support.
		** Set it to the highest supported frequency.
		*/ /* The user tried to set a frequency that is too low to support.
		** Set it to the lowest supported frequency.
		*/ /* Write the value to the SPI baud rate register. Section 23. SPI
	** of the PIC32 Family Reference Manual says to disable the SPI
	** controller before writing to the baud register
	*/ // disable SPI // enable SPI