1 / 17

Intro to MicroControllers : Stellaris Launchpad

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 /*

janice
Télécharger la présentation

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

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

  7. System Level Init //EnableFloating Point FPULazyStackingEnable(); //Set the clockspeed 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. 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.

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

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

  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, 115200, 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. 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.

  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, 2000000, 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)) { }

More Related