#include #include #include #include #include #include "sysctl.h" #include "hw_memmap.h" #include "hw_ints.h" #include "hw_nvic.h" #include "gpio.h" #include "hw_gpio.h" #include "hw_types.h" #include "pin_map.h" #include "adc.h" void clockInit(void); void gpioInit(void); void gpioInterruptConfig(void); void adcInit(void); /* ================================= Function Definitions ================================= */ /*! * @brief The purpose of this function is to configure system clock at 16MHz * @param[in] None. * @return None. */ void clockInit(void) { // Set the clock to run directly from the external crystal/oscillator at 16MHz. SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | \ SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); } /*! * @brief The purpose of this function is to initialize and configure the GPIO pins * @param[in] none ** @return NA */ void gpioInit(void) { uint32_t gpioPorts[6] = {SYSCTL_PERIPH_GPIOA, SYSCTL_PERIPH_GPIOB, SYSCTL_PERIPH_GPIOC,\ SYSCTL_PERIPH_GPIOD, SYSCTL_PERIPH_GPIOE, SYSCTL_PERIPH_GPIOF}; uint32_t indexCounter; g_initErrorFlag = false; //enable PortA, PortB, PortC, PortD, PortE and PortF for(indexCounter = 0; indexCounter < 6; indexCounter++) { SysCtlPeripheralEnable(gpioPorts[indexCounter]); while(!SysCtlPeripheralReady(gpioPorts[indexCounter])); } //Set the direction of the pins //Set PB4 to output GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4); //Set PB6 to output GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6); //Set PB7 to output GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7); //Set PF2 to output GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); //Set PF3 to output GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); //Configure PF4 to 2mA drive with weak pull-up GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, \ GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //Interrupt configuration gpioInterruptConfig(); } /*! * @brief The purpose of this function is to Configure GPIO Interrupts * @param[in] None * @return None */ void gpioInterruptConfig(void) { //Configure PE4 to 2mA drive with weak pull-down GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_4, \ GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); //Disable if any interrupt is enabled for PE4 GPIOIntDisable(GPIO_PORTE_BASE, GPIO_PIN_4); //Clear interrupts on PE4 GPIOIntClear(GPIO_PORTE_BASE, GPIO_PIN_4); //Register interrupts for PE4 GPIOIntRegister(GPIO_PORTE_BASE,GPIOE_Handler); //Set the interrupt type to detect on high edge GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_HIGH_LEVEL); //Enable the interrupt for PE4 GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_4); //Configure PB5 to 2mA drive with weak pull-down GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_5, \ GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); //Disable if any interrupt is enabled for PB5 GPIOIntDisable(GPIO_PORTB_BASE, GPIO_PIN_5); //Clear interrupts on PB5 GPIOIntClear(GPIO_PORTB_BASE, GPIO_PIN_5); //Register interrupts for PB5 //GPIOIntRegister(GPIO_PORTB_BASE,GPIOB_Handler); //Set the interrupt type to detect on high edge GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_HIGH_LEVEL); //Enable the interrupt for PE4 GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_5); } /*! * @brief This function is used to initialize and Configure ADC * @param[in] None. * @return NA */ void adcInit(void) { //Enable ADC0 module SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)); GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4|GPIO_PIN_5); //Set the clock configuration for ADC ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC|ADC_CLOCK_RATE_FULL, ADC_CLOCK_DIV1); //Set the reference for ADC ADCReferenceSet(ADC0_BASE, ADC_REF_INT); //Disable ADC sample sequencers before configuring ADCSequenceDisable(ADC0_BASE, ADC_SAMPLE_SEQUENCER1); //Configure ADC sample sequencer1 and sample sequencer2 ADCSequenceConfigure(ADC0_BASE, ADC_SAMPLE_SEQUENCER1, ADC_TRIGGER_PROCESSOR, 0U); //Configure inputs of sample sequencer1 ADCSequenceStepConfigure(ADC0_BASE, ADC_SAMPLE_SEQUENCER1, \ ADC_SS_STEP0, ADC_CTL_CH10); ADCSequenceStepConfigure(ADC0_BASE, ADC_SAMPLE_SEQUENCER1, \ ADC_SS_STEP1, ADC_CTL_CH11|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, ADC_SAMPLE_SEQUENCER1); } /*! * @brief This function is used to initialize GPIO and ADC peripherals * @param[in] None. * @return None */ None portInit(void) { //Initialize and configure all GPIO's gpioInit(); //Initialize ADC adcInit(); } /*** end of file ***/