Jump to content
43oh

SPI example for LM4F120


Recommended Posts

I tried looking around for a small SPI example I could use for my Launchpad in CCS, found nothing small.  I'm just looking to read and write to a register value, pretty much it for now.  I don't want to go with Energia right away, although it would probably be much simpler.

 

Any suggestions?

Link to post
Share on other sites

I tried looking around for a small SPI example I could use for my Launchpad in CCS, found nothing small.  I'm just looking to read and write to a register value, pretty much it for now.  I don't want to go with Energia right away, although it would probably be much simpler.

 

Any suggestions?

Look in stellarisWare\examples\peripherals\ssi

Link to post
Share on other sites

Hi

 

My adapted frequency analyzer code has  very simple SSI (SPI) code inside that was originally posted by Jordan Wills:

 

This is the initializing routine for a 3pin SPI  and the simple SPIWRITE routine I use to communicate with the SPI-device. 

 

cheers

CorB

//*****************************************************************************
//
// Initialize the SSI interface 
//
//*****************************************************************************
void
InitHWSSI()
{
	//
	// Initialize the 3 pins we will need for SPI communication with the LCD
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	// connect CS to pin E5
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0);
    // Connect SPI to PB4 (clock) and PB7(TX)
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinConfigure(GPIO_PB4_SSI2CLK);
	GPIOPinConfigure(GPIO_PB7_SSI2TX);
	GPIOPinTypeSSI(GPIO_PORTB_BASE, SSI_CLK | SSI_TX);

	//
	// Configure SSI2
	//
	SSIConfigSetExpClk(SSI2_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,  SSI_MODE_MASTER, SysCtlClockGet()/2, 16);

	//
	// Enable the SSI module.
	//
	SSIEnable(SSI2_BASE);


}

 
void SPIWrite(uint16_t command, uint16_t data)
{
uint16_t spidata;

spidata = command<<15;
spidata = spidata | data <<7;

SSIDataPut(SSI2_BASE, spidata);
//
// Wait until SSI is done transferring all the data in the transmit FIFO
//
while(SSIBusy(SSI2_BASE))
{
}

//
// Hit the SSI latch, locking in the data
//
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0);

}

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...