Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to MicroControllers : Stellaris Launchpad

Similar presentations

Presentation on theme: "Intro to MicroControllers : Stellaris Launchpad"— Presentation transcript:

1 Intro to MicroControllers : Stellaris Launchpad
Class 2: API Initialization & Use

2 Topics for Today Direct Register Access vs Software Driver Model
System Level vs Device Level Examples code for relevant devices

3 Direct Register Access
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

4 Software Driver Model Rapid development Simple Plain English Interface
Slightly less control (sometimes)

5 Example: Set SSI Clock Speed
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); OR SSI0_CR0_R = 0x000005c7; SSIConfigSetExpClk(SSI0_BASE, , SSI_FRF_MOTO_MODE_3, SSI_MODE_MASTER, ,8);

6 Layout of Program #includes //#defines & Global Variables
. //#defines & Global Variables //Other Functions (interrupt handlers, subfunctions, etc) int main(void){ //system level init //peripheral init //peripheral use }

7 System Level Init //Enable Floating Point FPULazyStackingEnable(); //Set the clock speed SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); IntMasterEnable();

8 Device Init //Config Enable System Peripheral (Pin Base) Set Pad Config (aka pin mux) Set Direction of Data //Use Read Write

9 Interrupts register handler, then enable, clear flag in interrupt handler
// Interrupt Init IntMasterEnable(); //System Level IntEnable(INT_GPIOA); //Device Level IntPrioritySet(INT_GPIOA, 0x00); //inverse priority // Interrupt functions IntPendClear(INT_GPIOA); //remove pending interrupt from que IntDisable(INT_GPIOA); IntMasterDisable(); 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.

10 Devices GPIO Timers Hibernate I2C UART SSI (aka SPI) ADC


12 UART //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, , SysCtlClockGet()); //UART functions UARTprintf(“text to print”);

13 Timers //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

14 Hibernate 32 bit RTC, 15bit sub second timer, battery backed memory
Hibernate is complicated, go look at Page 197 for examples.

15 Analog to Digital Converter (ADC)
// 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); //trigger sample while(!ADCIntStatus(ADC0_BASE, 0, false)){} //wait until sampling complete ADCSequenceDataGet(ADC0_BASE, 0, &ulValue); //get data

16 SSI // SSI Init SSIConfigSetExpClk(SSI_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE0, SSI_MODE_MASTER, , 8); SSIEnable(SSI_BASE); // SSI functions SSIDataGet(SSI_BASE, &data); SSIDataPut(SSI_Base,data);

17 I2C // 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)) { }

Download ppt "Intro to MicroControllers : Stellaris Launchpad"

Similar presentations

Ads by Google