0

我正在执行一项任务,以读取焊接到 cc2530 电池板上 GPIO 引脚的传感器产生的值。三种不同类型的传感器焊接在其上;温度(模拟,输出电压),光(模拟,输出频率)和气压计(模拟)。

我已经能够成功读取温度并正确显示数字(示例在 contiki git repo 中提供),但我无法手动配置 GPIO 引脚以从光电二极管读取。

请提供任何帮助

P0SEL &= ~0x04; /* Set as GPIO */
P0DIR &= ~0x04; /* Set as Input */
P0INP |= 0x04; /* Set as tri-state */
4

1 回答 1

1

找到了。

这是从 cc2530 上的 pin 读取的示例代码:

static void ReadLightSensor(void)
 {
                    //select pin in hex form
        P0SEL &= ~0x10; /* Set pin (sample) as GPIO */
        P0DIR &= ~0x10; /* Set pin as input*/
        P0INP |= 0x10;  /* Set as tri-state*/
        APCFG |= 0x10;  /* configure ADC on pin*/

        ADCCON3 = 0x34; /*This represents the paramters passed into ADCCON3*/

        while (!ADCIF);
        ADCIF = 0;

        tv = ADCL;
        tv |= (((unsigned short) ADCH) << 8);
        tv >>= 4 ;
        lv = tv;
                    PRINTF("Pin reading = 0x%04x\n\r", lv);
于 2013-09-12T17:39:26.373 回答