Intro to microcontrollers stellaris launchpad
This presentation is the property of its rightful owner.
Sponsored Links
1 / 17

Intro to MicroControllers : Stellaris Launchpad PowerPoint PPT Presentation


  • 110 Views
  • Uploaded on
  • Presentation posted in: General

Intro to MicroControllers : Stellaris Launchpad. Class 2: API Initialization & Use. Topics for Today. Direct Register Access vs Software Driver Model System Level vs Device Level Examples code for relevant devices. Direct Register Access. Total Control but more tedious inc /*

Download Presentation

Intro to MicroControllers : Stellaris Launchpad

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Intro to microcontrollers stellaris launchpad

Intro to MicroControllers : Stellaris Launchpad

Class 2:

API Initialization & Use


Topics for today

Topics for Today

  • Direct Register Access vs Software Driver Model

  • System Level vs Device Level

  • Examples code for relevant devices


Direct register access

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


Software driver model

Software Driver Model

  • Rapid development

  • Simple Plain English Interface

  • Slightly less control (sometimes)


Example set ssi clock speed

Example: Set SSI Clock Speed


Layout of program

Layout of Program

#includes

.

.

.

//#defines & Global Variables

.

.

.

//Other Functions (interrupt handlers, subfunctions, etc)

.

.

.

int main(void){

//system level init

//peripheral init

.

.

.

//peripheral use

}


System level init

System Level Init

//EnableFloating Point

FPULazyStackingEnable();

//Set the clockspeed

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |

SYSCTL_XTAL_16MHZ);

IntMasterEnable();


Device init

Device Init

//Config

Enable System Peripheral (Pin Base)

Set Pad Config (aka pin mux)

Set Direction of Data

//Use

Read

Write


Interrupts register handler then enable clear flag in interrupt handler

Interruptsregister 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.


Devices

Devices

  • GPIO

  • Timers

  • Hibernate

  • I2C

  • UART

  • SSI (aka SPI)

  • ADC


Gpio 8 pins per port

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


Intro to microcontrollers stellaris launchpad

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, 115200, SysCtlClockGet());

//UART functions

UARTprintf(“text to print”);


Timers

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


Hibernate 32 bit rtc 15bit sub second timer battery backed memory

Hibernate32 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.


Analog to digital converter adc

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


Intro to microcontrollers stellaris launchpad

SSI

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


Intro to microcontrollers stellaris launchpad

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

{

}


  • Login