Jump to content
Sign in to follow this  
elimpnick

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?

Share this post


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

Share this post


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);

}

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×