通过Timer1的compare event来启动ADC的问题
时间:10-02
整理:3721RD
点击:
我尝试用Timer 1 channel 0的compare event来触发ADC 的sequence采样。
在调试的时候,从IAR里看到TIMER1已经启动,尝试放个中断进去也能被触发。
但是在IAR里查看ADC结果寄存器的读数一直是零。ADC应该是没有启动,用来读取ADC结果的DMA也没有被触发。
寄存器配置如下:
T1STAT = ~T1STAT_CH0IF; // Set individual interrupt enable bit in the peripherals SFR. //T1CCTL0 |= T1CCTLn_IM; // Enable interrupt on channel 0. /*T1CCTL1 &= ~T1CCTLn_IM; // Disable interrupt on channel 1. T1CCTL2 &= ~T1CCTLn_IM; // Disable interrupt on channel 2. T1CCTL3 &= ~T1CCTLn_IM; // Disable interrupt on channel 3. T1CCTL4 &= ~T1CCTLn_IM; // Disable interrupt on channel 4. T1OVFIM = 0; // Disable overflow interrupt.*/ // Enable Timer 1 interrupts by setting [IEN1.T1IE=1]. //T1IE = 1; //global inten //EA = 1; //test the adc interruption //IEN0 |= 0X02; //set I/O state //alternative 0 /*PERCFG &= ~(0x40); //alternative control 4 timer 1 P2DIR =(P2DIR & ~(0xc0)) | 0x80; //alternative priority:1000 0000 P0SEL |= 0x04; //set P0_2 as peripheral P0DIR |= 0x04; //Set p0.2 as output*/ //alternative 1 PERCFG |= 0x40; // Select Timer 1 Alternative 1 location //x1xx xxxx P2SEL = (P2SEL & ~0x10); // Give priority to Timer 1 //xxx0 xxxx P1DIR |= 0x04; // Set P1.2 to output P1SEL |= 0x04; // Set P1.2 to peripheral // Set channel 0 to compare mode and to toggle on compare. T1CCTL0 = ((T1CCTL0 & ~T1CCTLn_CMP) | T1CCTLn_CMP_TOG_ON_CMP | T1CCTLn_MODE) & ~T1CCTLn_IM; //0 // Set compare register of channel 0 to 32767 ( 0xFFFF / 2 ). T1CC0L = 0xE8; T1CC0H = 0x03; // Set prescaler divider value to 32 to get a tickspeed of 500 kHz and // set Timer 1 to free running mode. T1CTL = (T1CTL & ~(T1CTL_MODE | T1CTL_div)) | T1CTL_MODE_MODULO | T1CTL_div_32; //now timer 1 starts
adc部分的寄存器配置如下:
APCFG |= 0x01; //P0_0 as adc input, this would override the P0SEL // Set [ADCCON2.SREF/Sdiv/SCH] bits according to ADC configuration. ADCCON2 = 0x00 | ADCCON2_Sdiv_512 | ADCCON2_SCH_TEMPR; //note that the ref is set to internal reference // Set [ADCCON1.STSEL] to continues conversion. ADCCON1 = (ADCCON1 & ~ADCCON1_STSEL) | ADCCON1_STSEL_T1C0_CMP_EVT; //Set STSEL and leave other original
请问是基于CC2541的什么示例代码开发的?
SimpleBLEPeripheral。这些寄存器的初始化是放在simpleBLEPeripheral task的按键处理函数里的。不过这个好像关系不大?
请问ADC和DMA的宏定义都打开了吗?
预处理里定义了HAL_DMA=TRUE和HAL_ADC=TRUE啊
如果不用timer来触发,直接在初始化的时候就触发,是否都能正常工作?如果可以,对比检查一下时序,以及看看是不是有些操作没有做。如果不行,说明初始化就有问题,可以参考sensortag的source code来检查。