SPI Mode

Mode  CPOL  CPHA
0     0     0     Clock idle low, data is clocked in on rising edge, output data (change) on falling edge
1     0     1     Clock idle low, data is clocked in on falling edge, output data (change) on rising edge
2     1     0     Clock idle high, data is clocked in on falling edge, output data (change) on rising edge
3     1     1     Clock idle high, data is clocked in on rising edge, output data (change) on falling edge

Using SPI bus master

//IN YOUR INITIALSE CODE
	//----- SETUP SPI 1 -----
	//Used for: 
	//Setup SPI using MCC:
	//	Setup SPI:
	//		(The following configures port for SPI Master Mode 3)
	//		Master Mode
	//		Clock Polarity Select Bit: Idle state is high, active state is low
	//		SPI Clock Edge Select Bit: Serial output data changesa on transition from Idle clock state to active clock state
	//		SPI Data Input Sample Phase Bit: Input data sampled at middle of data output time
	//		Master Mode Slave Select Enable Bit: Slave select SPI support is disabled
	//		Data Width: 8-bit
	//		Master Clock Enalbe Bit: PBCLK2 is used by the Baud Rate Generator
	//		Baud Rate in Hz: 1,000,000
	//		Dummy Data: 0xFF
	//	Setup interrupts:
	//		Enable SPI1 Fault Interrupt = Can be left set to Off
	//		Enable SPI1 Receive Done Interrupt = Will already be set to Enabled
	//		Enable SPI1 Transmit Done Interrupt: Will already be set to Enabled
	//		Priority (set for all): 1	//<<<Set as required for your application
	//		Subpriority (set for all): 0	//<<<Set as required for your application

	//SPI1_CallbackRegister(SPI1_MyEventHandler,(uintptr_t)NULL);		//Register my callback function to be called when the SPI operation completes (optional)


//HOW TO PERFORM A WRITE READ OPERATION
	uint8_t RxData[3];									//Can be uint8_t, uint16_t or uint32_t depending on your SPI port Data Width setting
	uint8_t TxData[3] = {0xff, 0xff, 0xff};				//Can be uint8_t, uint16_t or uint32_t depending on your SPI port Data Width setting
	if (SPI1_WriteRead(&TxData[0], 3, &RxData[0], 3))	//<<< RxData or TxData can be set as NULL and length to 0 if you don't care about the rx or tx side of the data transfer
	{
		//WRITE READ STARTED

		while (SPI1_IsBusy())
			;

		//WRITE READ COMPLETED


	}


//*************************************************
//*************************************************
//********** SPI1 OPERATION COMPLETE IRQ **********
//*************************************************
//*************************************************
/*
void SPI1_MyEventHandler (uintptr_t context)
{
	
 
}
*/
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *