TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2541 再打开Timer3 和Timer4时,会触发P1.2外部中断

我目前使用CC2541的Timer3 和Timer4 作为PWM信号的timer,P1,2作为一个外部中断接口,接收外部中断。

目前遇到一个问题,就是当配置完Timer3,Timer4 以及中断接口P1.2后,开始Timer4 和Timer3 时,好像概率的会触发一个P1.2的中断。测试时已经将强制P1.2拉到地,还是莫名的会运行中断处理函数。

请问这是什么原因?下面是我的代码。

P1SEL |= BV(1); //P1.1 for pwm
P1DIR |= BV(1); //P1.1 as output.// Init Timer4 for PWM
P2SEL |= 0x18; //P2SEL.PRI1P1 and P2SEL.PRI0P1;
PERCFG &= 0xef; //PERCFG.T4CFG, alt 0
T4CC1 = 0x80;
T4CCTL1 = 0x24; //00100100
T4CTL |= 0x60; //01100000 timer start
T4CTL |= 0x04;

P1SEL |= BV(3); //P1.3 for pwm
P1DIR |= BV(3); //P1.3 as output.// Init Timer3 for PWM
P2SEL |= 0x60; //P2SEL.PRI2P1 , P2SEL.PRI3P1 ;
PERCFG &= 0xdf; //PERCFG.T4CFG, alt 0
T3CC0 = 0x80;
T3CCTL0 = 0x24; //00 100 1 00
T3CTL |= 0x60; //011 0 0 0 00 timer start
T3CTL |= 0x04;

// Set interupt for p1.2P1SEL &= ~(BV(2)); /* Set pin function to GPIO */
P1DIR &= ~(BV(2)); /* Set pin direction to Input */
P1IEN |= BV(2);
P1IFG &= ~(BV(2));

PICTL &= ~(BV(1)); // set P1 Rising edge
IEN2 |= BV(4) ; // enable P1 interupt

// start PWM
T4CTL |= 0x10;
T3CTL |= 0x10;

Susan Yang:

/******************************************************************************@filebuzzer.c@brief Control of the buzzer of the keyfob board in the CC2540DK-mini kit.Group: WCS, BTSTarget Device: CC2540, CC2541******************************************************************************Copyright (c) 2009-2019, Texas Instruments IncorporatedAll rights reserved.IMPORTANT: Your use of this Software is limited to those specific rightsgranted under the terms of a software license agreement between the userwho downloaded the software, his/her employer (which must be your employer)and Texas Instruments Incorporated (the "License"). You may not use thisSoftware unless you agree to abide by the terms of the License. The Licenselimits your use, and you acknowledge, that the Software may not be modified,copied or distributed unless embedded on a Texas Instruments microcontrolleror used solely and exclusively in conjunction with a Texas Instruments radiofrequency transceiver, which is integrated into your product. Other than forthe foregoing purpose, you may not use, reproduce, copy, prepare derivativeworks of, modify, distribute, perform, display or sell this Software and/orits documentation for any purpose.YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION AREPROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALLTEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHERLEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSESINCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVEOR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENTOF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.Should you have any questions regarding your right to use this Software,contact Texas Instruments Incorporated at www.TI.com.******************************************************************************Release Name: ble_sdk_1.5.0.16Release Date: 2019-04-18 08:53:32*****************************************************************************/#include "hal_mcu.h"
#include "buzzer.h"/** \brief	Initialize buzzer
*
* This will initialize the buzzer
*
*/
void buzzerInit(void)
{
#if defined ( CC2540_MINIDK )// Buzzer connected at P1_6// We will use Timer 3 Channel 0 at alternate location 2// Channel 0 will toggle on compare with 0 and counter will// count in up/down mode to T3CC0.PERCFG |= 0x20;// Timer 3 Alternate location 2P1DIR |= 0x40;// P1_6 = outputP1SEL |= 0x40;// Peripheral function on P1_6T3CTL &= ~0x10;// Stop timer 3 (if it was running)T3CTL |= 0x04;// Clear timer 3T3CTL &= ~0x08;// Disable Timer 3 overflow interruptsT3CTL |= 0x03;// Timer 3 mode = 3 - Up/DownT3CCTL0 &= ~0x40;// Disable channel 0 interruptsT3CCTL0 |= 0x04;// Ch0 mode = compareT3CCTL0 |= 0x10;// Ch0 output compare mode = toggle on compare
#endif
}/** \brief	Starts the buzzer
*
* Starts the buzzer with given frequency
*
* \param[in]frequency
*The frequency in Hertz of the sound to output
* @return1 successful - 0 if frequency invalid
*/
uint8 buzzerStart(uint16 frequency)
{
#if defined ( CC2540_MINIDK )buzzerInit();uint8 prescaler = 0;// Get current Timer tick divisor settinguint8 tickSpdDiv = (CLKCONSTA & 0x38)>>3;// Check if frequency too lowif (frequency < (244 >> tickSpdDiv)){// 244 Hz = 32MHz / 256 (8bit counter) / 4 (up/down counter and toggle on compare) / 128 (max timer prescaler)buzzerStop();// A lower tick speed will lower this number accordingly.return 0;}// Calculate nr of ticks required to achieve target frequencyuint32 ticks = (8000000/frequency) >> tickSpdDiv;// 8000000 = 32M / 4;// Fit this into an 8bit counter using the timer prescalerwhile ((ticks & 0xFFFFFF00) != 0){ticks >>= 1;prescaler += 32;}// Update registersT3CTL &= ~0xE0;T3CTL |= prescaler;T3CC0 = (uint8)ticks;// Start timerT3CTL |= 0x10;
#endifreturn 1;
}/** \brief	Stops the buzzer
*
* Turn off the buzzer
*
*/
void buzzerStop(void)
{
#if defined ( CC2540_MINIDK )T3CTL &= ~0x10;// Stop timer 3P1SEL &= ~0x40;P1_6 = 0;
#endif
}

Susan Yang:

“好像概率的会触发一个P1.2的中断”

也就是说不是每次都会进入中断?有没有在线调试过?

关于PWM配置,建议您参考上面的方式

赞(0)
未经允许不得转载:TI中文支持网 » CC2541 再打开Timer3 和Timer4时,会触发P1.2外部中断
分享到: 更多 (0)