Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: CORTEX_M4_0 - Debug Call Stack ERROR MSP432

$
0
0
#include "msp.h" #include "driverlib.h" #include #include #include #define INITIAL_DUTY_CYCLE 10 /* ADC results buffer */ static uint16_t resultsBuffer[2]; unsigned volatile int state; unsigned volatile int frequency; unsigned volatile int volume; unsigned volatile int buttonPressed; unsigned volatile int duty_cycle; void init_timer(void); void mapports(void); /* * Main function */ void main(void) { /* Halting WDT and disabling master interrupts */ MAP_WDT_A_holdTimer(); MAP_Interrupt_disableMaster(); MAP_CS_setDCOFrequency(10000000); /* 10MHz */ mapports(); init_timer(); MAP_Interrupt_disableSleepOnIsrExit(); // Specify that after an interrupt, the CPU wakes up MAP_Interrupt_enableMaster();// unmask IRQ interrupts to allow the CPU to respond. /*SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; // Specify that after an interrupt, the CPU wakes up //__enable_interrupt();// unmask IRQ interrupts toallow the CPU to respond. NVIC->ISER[0] = 1 KEYID=PMAP_KEYID_VAL; // unlock PMAP P2MAP->PMAP_REGISTER7=PMAP_TA0CCR0A; // map TA0CCR0 to P2.7 as primary module PMAP->KEYID=0; // relock PMAP until next hard reset } const Timer_A_CompareModeConfig ccr4_Config = { TIMER_A_CAPTURECOMPARE_REGISTER_4, TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_A_OUTPUTMODE_RESET_SET, INITIAL_DUTY_CYCLE }; void TA0_0_Handler() { //change resultsBuffer[0] & [1] to correct frequency and volume frequency = 1/((0.8887*(resultsBuffer[0]))+100)*1000000; TIMER_A0->CCTL[0] &= ~TIMER_A_CCTLN_CCIFG; // clear flag //states on and off if (buttonPressed && state){ // pause TIMER_A0->CCR[0] = 0; state = 0; } if (buttonPressed && ~state) { // play TIMER_A0->CCR[0] = frequency; state = 1; } //set volume MAP_Timer_A_setCompareValue(TIMER_A0_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_4,duty_cycle); } void init_timer(){ // initialize and start timer // Initializes Clock System /*MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 ); MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 ); MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 ); MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);*/ // Configures Pin 6.0 and 4.4 as ADC input MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN0, GPIO_TERTIARY_MODULE_FUNCTION); MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN4, GPIO_TERTIARY_MODULE_FUNCTION); // Initializing ADC (ADCOSC/64/8) MAP_ADC14_enableModule(); MAP_ADC14_initModule(ADC_CLOCKSOURCE_ADCOSC, ADC_PREDIVIDER_64, ADC_DIVIDER_8, 0); // Configuring ADC Memory (ADC_MEM0 - ADC_MEM1 (A15, A9) with repeat) with internal 2.5v reference MAP_ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM1, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A15, ADC_NONDIFFERENTIAL_INPUTS); MAP_ADC14_configureConversionMemory(ADC_MEM1, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A9, ADC_NONDIFFERENTIAL_INPUTS); // Enabling the interrupt when a conversion on channel 1 (end of sequence) is complete and enabling conversions MAP_ADC14_enableInterrupt(ADC_INT1); // Enabling Interrupts MAP_Interrupt_enableInterrupt(INT_ADC14); MAP_Interrupt_enableMaster(); // Setting up the sample timer to automatically step through the sequence convert. MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION); // Triggering the start of the sample MAP_ADC14_enableConversion(); MAP_ADC14_toggleConversionTrigger(); TIMER_A0->CTL |= TIMER_A_CTL_CLR ;// reset clock TIMER_A0->CTL = TIMER_A_CTL_TASSEL_2 // clock source = SMCLK | TIMER_A_CTL_ID_0 // clock prescale=1 | TIMER_A_CTL_MC_1; // Up mode TIMER_A0->EX0 = TIMER_A_EX0_TAIDEX_2; // divisor=3 // set CCR0 compare mode, output mode 4 (toggle), flag clear, enable interrupt TIMER_A0->CCTL[0]= TIMER_A_CCTLN_OUTMOD_4+TIMER_A_CCTLN_CCIE+TIMER_A_CCTLN_CCIFG; //MAP_Timer_A_initCompare(TIMER_A0_BASE, &ccr0_Config); MAP_Timer_A_initCompare(TIMER_A0_BASE, &ccr4_Config); MAP_Timer_A_registerInterrupt(TIMER_A0_BASE,TIMER_A_CCR0_INTERRUPT,TA0_0_Handler); GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN7,GPIO_PRIMARY_MODULE_FUNCTION); MAP_Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE); // start TA0 in up mode TIMER_A0->CCR[0] = 1/10000*1000000; // set first frequency of TACCRO P2->SEL0|=BIT7; // connect timer output to pin P2->DIR |=BIT7; // output mode on P2.7 } void ADC14_IRQHandler(void) { uint64_t status; status = MAP_ADC14_getEnabledInterruptStatus(); MAP_ADC14_clearInterruptFlag(status); /* ADC_MEM1 conversion completed */ if(status & ADC_INT1) { /* Store ADC14 conversion results */ resultsBuffer[0] = ADC14_getResult(ADC_MEM0); resultsBuffer[1] = ADC14_getResult(ADC_MEM1); /* Determine if JoyStick button is pressed */ buttonPressed = 0; if (!(P4IN & GPIO_PIN1)) buttonPressed = 1; } }

Viewing all articles
Browse latest Browse all 62309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>