Class 2:
API Initialization & Use
• Direct Register Access vs Software Driver
Model
• System Level vs Device Level
• Examples code for relevant devices
• Total Control but more tedious
• inc /*
– Header files for DRA (inc/lm4fh5qr.h)
• *_R files used to access register
• *_M used as mask
• *_S used to shift
• Rapid development
• Simple Plain English Interface
• Slightly less control (sometimes)
Direct Register Access (pg 925) Software Driver Model (pg 336)
SSI0_CR0_R = ((5 << SSI_CR0_SCR_S) | SSI_CR0_SPH |
SSI_CR0_SPO | SSI_CR0_FRF_MOTO | SSI_CR0_DSS_8);
SSIConfigSetExpClk(SSI0_BASE, 50000000,
SSI_FRF_MOTO_MODE_3, SSI_MODE_MASTER, 1000000,8);
OR
SSI0_CR0_R = 0x000005c7;
}
#includes
.
.
.
//#defines & Global Variables
.
.
.
//Other Functions (interrupt handlers, subfunctions, etc)
.
.
.
int main(void){
//system level init
.
.
.
//peripheral init
//peripheral use
//Enable Floating Point
FPULazyStackingEnable();
//Set the clock speed
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
IntMasterEnable();
//Config
Enable System Peripheral (Pin Base)
Set Pad Config (aka pin mux)
Set Direction of Data
//Use
Read
Write
register handler, then enable, clear flag in interrupt handler
// Interrupt Init
IntMasterEnable();
IntEnable(INT_GPIOA);
//System Level
//Device Level
IntPrioritySet(INT_GPIOA, 0x00); //inverse priority
// Interrupt functions
IntPendClear(INT_GPIOA);
IntDisable(INT_GPIOA);
IntMasterDisable();
//remove pending interrupt from que
You can register / unregister interrupts on the fly, but it does so by loading the NVIC
Table into RAM, I would advise against this and make your interrupts static at compile time. The NVIC can be found in the startup_rvmdk.c file in the project root.
• GPIO
• Timers
• Hibernate
• I2C
• UART
• SSI (aka SPI)
• ADC
8 pins per port
//GPIO Init
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1);
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2);
GPIOPinConfigure();
//GPIO Functions
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, GPIO_PIN_1);
GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_1, GPIO_PIN_2);
//UART Init
#include "utils/uartstdio.c "
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig(0, 115200, SysCtlClockGet());
//UART functions
UARTprintf(“text to print”);
//Timer Init
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //32bit periodic
TimerLoadSet(TIMER0_BASE, TIMER_A, LengthOfTime); //duration for timer
TimerEnable(TIMER0_BASE, TIMER_A);
//Timer functions usually used as timer interrupts
NOTE: LengthOfTime is in system ticks, to calculate real time use this equation
Realtime=(1/ClockSpeed)*LengthOfTime
32 bit RTC, 15bit sub second timer, battery backed memory
Hibernate is complicated, go look at http://www.ti.com/lit/ug/spmu019o/spmu019o.pdf
Page 197 for examples.
// ADC Init
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_IE | ADC_CTL_END |
ADC_CTL_CH0 );
ADCSequenceEnable(ADC0_BASE, 0);
// ADC functions int ulValue;
ADCProcessorTrigger(ADC0_BASE, 0); while(!ADCIntStatus(ADC0_BASE, 0, false)){}
ADCSequenceDataGet(ADC0_BASE, 0, &ulValue);
//trigger sample
//wait until sampling complete
//get data
// SSI Init
SSIConfigSetExpClk(SSI_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE0,
SSI_MODE_MASTER, 2000000, 8);
SSIEnable(SSI_BASE);
// SSI functions
SSIDataGet(SSI_BASE, &data);
SSIDataPut(SSI_Base,data);
// Initialize Master and Slave
I2CMasterInitExpClk(I2C_MASTER_BASE, SysCtlClockGet(), true);
// Specify slave address
I2CMasterSlaveAddrSet(I2C_MASTER_BASE, 0x3B, false);
// Place the character to be sent in the data register
I2CMasterDataPut(I2C_MASTER_BASE, ’Q’);
// Initiate send of character from Master to Slave
I2CMasterControl(I2C_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
}
{
// Delay until transmission completes while(I2CMasterBusBusy(I2C_MASTER_BASE))