Hi Yan,
硬件已经做成这样只能用timer 1了,通过看swru191c.pdf里timer 1的寄存器,软件修改如下:
void buzzerInit(void)
[
#if defined ( CC2540_MINIDK )
// Buzzer connected at P1_2
// We will use Timer 1 Channel 0 at alternate location 2
// Channel 0 will toggle on compare with 0 and counter will
// count in up/down mode to T1CC0.
PERCFG |= 0x40; // Timer 1 Alternate location 2
P1DIR |= 0x04; // P1_2 = output
P1SEL |= 0x04; // Peripheral function on P1_2
T1STAT |= 0x20; // Disable Timer 1 overflow interrupts
T1CTL |= 0x03; // Timer 1 mode = 1 - Up/Down
T1CCTL0 &= ~0x40; // Disable channel 0 interrupts
T1CCTL0 |= 0x04; // Ch0 mode = compare
T1CCTL0 |= 0x10; // Ch0 output compare mode = toggle on compare
#endif
]
uint8 buzzerStart(uint16 frequency)
[
#if defined ( CC2540_MINIDK )
uint8 prescaler = 0;
// Get current Timer tick divisor setting
uint8 tickSpdDiv = (CLKCONSTA & 0x38)>>3;
// Check if frequency too low
if (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 frequency
uint32 ticks = (8000000/frequency) >> tickSpdDiv; // 8000000 = 32M / 4;
// Fit this into an 8bit counter using the timer prescaler
while ((ticks & 0xFFFF0000) != 0)
[
ticks >>= 1;
prescaler += 4;
]
// Start timer
T1CTL |= 0x03; // Timer 1 mode - Up/Down
// Update registers
T1CTL &= ~0x0C;
T1CTL |= prescaler;
T1CC0H = (uint8)(ticks>>8);
T1CC0L = (uint8)ticks;
#endif
return 1;
]
void buzzerStop(void)
[
#if defined ( CC2540_MINIDK )
T1CTL &= ~0x03; // Stop timer 1
#endif
]
发现PIO1-2上输出的波形是不联系的,单就timer 1的设置来看,这一段配置有什么问题吗?