我正在使用BOOSTXL回放作为在MSP430FR5994上运行音频检测代码的参考。 使用的MSP是外部的,并且由启动板成功检测到。 在我的代码中,我已将外部麦克风配置为提供从低到高的转换,该转换将作为从LPM唤醒设备的中断。 'main.c'文件中的代码如下:
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
initClock();
initGpio();
PM5CTL0 &= ~LOCKLPM5; // Clear lock bit
// Set internal reference voltage to 2.0 V
//REFCTL0 = REFVSEL_1; //vm1010
// vm1010 mode pin (P6.1), o/p, low at start for normal mode
P6OUT &= ~BIT1; // vm1010
P6DIR |= BIT1; // vm1010
// vm1010 mic power on (P6.2)
P6OUT |= BIT2; // vm1010
P6DIR |= BIT2; // vm1010
// vm1010 mode pin, o/p, high for WoS mode
P6OUT |= BIT1; // vm1010
P5IFG &= ~BIT6; // Clear interrupt on P5.6
P5IE |= BIT6; // Enable interrupt on P5.6
P5IFG &= ~BIT5; // Clear interrupt on P5.5
P5IE |= BIT5; // Enable interrupt on P5.5
// vm1010
P5IFG &= ~BIT7; // Clear interrupt on P5.7
P5IE |= BIT7; // Enable interrupt on P5.7
__bis_SR_register(GIE);
runApplication();
return 1;
}
void initGpio(void)
{
// Configure switches to have pull up resistors
P5DIR &= ~(BIT6|BIT5); // Set P5.6 and P5.5 to input direction
P5REN |= (BIT6|BIT5); // Enable option of pull-up or pull-down resistors for P5.6 P5.5
P5OUT |= (BIT6|BIT5); // Enable pull-up resistor for P5.6 and P5.5
// Configure switch pins to generate interrupts on high to low transitions
P5IES |= BIT6;
P5IES |= BIT5;
// vm1010 WoS digital out pin, i/p
P5DIR &= ~BIT7; // Set P5.7 to input direction // vm1010
P5REN |= BIT7; // Enable pull-up or pull-down resistors // vm1010
P5OUT &= ~BIT7; // Enable pull-down resistor for P5.7
//Configure vm1010 digi o/p pin to generate interrupts on low to high transitions
P5IES &= ~BIT7; // vm1010
}
随后,在运行应用程序的'application.c'文件中,我正在使用调试器验证代码的功能。 在这里,runApplication() 函数控制执行,在此中我使用两种模式-默认和录音,用于表示麦克风的使用。 此函数的代码如下所示:
void runApplication(void)
{
while(1)
{
P5IE &= ~BIT7; // Disable interrupt on P5.7 // vm1010
P5IE &= ~BIT6; // Disable interrupt on P5.6
P5IE &= ~BIT5; // Disable interrupt on P5.5
switch(applicationMode)
{
case RECORD:
{
volatile uint16_t j;
runRecord();
amplify_data();
fft_init();
while(window_number < 64)
{
fft_cal();
}
window_number=0;
for(j = 1; j < (VECTOR_SIZE / 2); j++) // vm1010
{
// vm1010
real = fft_res[2 * j] << 2;
imag = fft_res[2 * j + 1] << 2;
if(real < 0)
{
real_abs = ~real + 1;
}
else
{
real_abs = real;
}
if(imag < 0)
{
imag_abs = ~imag + 1;
}
else
{
imag_abs = imag;
}
if(real_abs >= imag_abs)
{
max = real_abs;
min = imag_abs;
}
else
{
max = imag_abs;
min = real_abs;
}
mag = max + 3 * (min >> 3);
FFT_data[j] = mag << 1;
}
int16_t spectrum[SIGNAL_ROWS1][SIGNAL_COLS1];
signed int a,b;
for(a=0; a<1; a++)
{
for(b=256; b>=0; b--)
{
spectrum[a][b] = FFT_data[b];
}
}
matrix_multiply(1, 256, 256, 20, spectrum, weights1, pdt1);
matrix_add(1, 20, pdt1, bias1, layer1);
act_funct(1, 20, layer1, act1);
matrix_multiply(1, 20, 20, 10, act1, weights2, pdt2);
matrix_add(1, 10, pdt2, bias2, layer2);
act_funct(1, 10, layer2, act2);
matrix_multiply(1, 10, 10, 2, act2, weights3, pdt3);
matrix_add(1, 2, pdt3, bias3, layer3);
act_out(1, 2, layer3, pred);
if(pred[0][0]==1)
{
//PM5CTL0 &= ~LOCKLPM5;
// TB0.6 ---- P3.7 ---- PWM 4kHz for buzzer
TB0CCR0 = 2000-1; // PWM Period, 4kHz --> 250 us --> 2000 (0 to 1999) ticks at SMCLK = 8MHz
TB0CCTL6 = OUTMOD_7; // CCR6 reset/set
TB0CCR6 = 1000; // CCR6 PWM duty cycle, 50% duty cycle, 1000 ticks
TB0CTL = TBSSEL__SMCLK | MC__UP | TBCLR; // SMCLK, up mode, clear TBR
P1OUT |= BIT0;
// TA1.1 ---- P1.2 ---- Timer for approx. 3 seconds for buzzer and LED
TA1CTL = TASSEL__SMCLK | MC__CONTINUOUS | TACLR | TAIE; // SMCLK, Continuous mode, clear TAR
__bis_SR_register(LPM4_bits + GIE); // Enter LPM4 w/ interrupt
P1OUT &= ~BIT0;
TA1CTL &= ~MC;
TB0CTL &= ~MC;
}
memset(fft_res, 0, sizeof(fft_res));
memset(FFT_data, 0, sizeof(signal_fft));
break;
}
default:
break;
}
applicationMode = DEFAULT;
// Need to put in normal mode and back to WoS mode to avoid issue where continuous clapping
// causes interrupts faster than we can go in sleep mode, thus causing a state where we
// are in sleep mode, but the interrupt is not recognized since interrupt flag is already high and
// not cleared
// vm1010 mode pin, o/p, low for normal mode
P6OUT &= ~BIT1; // vm1010
// Set a Switch debounce to 10ms (500ms -- 0.5 * sys freq)
__delay_cycles(0.01 * __SYSTEM_FREQUENCY_MHZ__);
P5IFG &= ~BIT6; // Clear interrupt on P5.6
P5IE |= BIT6; // Enable interrupt on P5.6
P5IFG &= ~BIT5; // Clear interrupt on P5.5
P5IE |= BIT5; // Enable interrupt on P5.5
P5IFG &= ~BIT7; // Clear interrupt on P5.7 // vm1010
P5IE |= BIT7; // Enable interrupt on P5.7 // vm1010
// vm1010 mode pin, o/p, high for WoS mode
P6OUT |= BIT1; // vm1010
__bis_SR_register(LPM4_bits + GIE);
}
}
在调试模式下,当我在启动板上结合BOOSTXL BoosterPack使用MSP时,我使用按钮从LPM4中唤醒,然后转到CASE =记录并开始录制。
但是,当我使用外置麦克风时,我想使用在WFP 5.7 上获得的数字输出作为中断,以便从LPM4中唤醒。 该ISR的编写方式如下:
#pragma vector=PORT5_VECTOR
__interrupt void port5IsrHandler(void)
{
switch (__even_in_range(P5IV, P5IV_P5IFG7))
{
case P5IV_NONE:
break;
case P5IV_P5IFG0:
break;
case P5IV_P5IFG1:
break;
case P5IV_P5IFG2:
break;
case P5IV_P5IFG3:
break;
case P5IV_P5IFG4:
break;
case P5IV_P5IFG5:
case P5IV_P5IFG6:
// Toggle record mode
applicationMode = RECORD ;
//exit LPM mode on exit
__bic_SR_register_on_exit(LPM0_bits);
break;
case P5IV_P5IFG7:
// Toggle record mode
applicationMode = RECORD;
//exit LPM mode on exit
__bic_SR_register_on_exit(LPM0_bits);
break;
default:
break;
}
}
但是,在调试过程中,我的代码成功地完成了该函数,直到它进入runApplication() 函数中的LPM4 -__bis_sr_register(LPM4_bit + GIE)。 但是,当我在设备进入LPM后运行调试器时,我的代码将持续运行,而不会在函数中分支到记录模式。 在浏览了这里发布的多个示例和各种问题后,我仍然不确定我可能会做什么错误。 如需进一步帮助澄清问题,请告知我是否需要任何其他信息。
谢谢你。