This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC430 ADC12MEM register always reads 4095

Other Parts Discussed in Thread: SYSBIOS, CC430F6137

Hi, I am working on reading an analog sensor, which gives output between 4 and 20 miliamps. I've initialized ADC12, it works but it always produces 0x0FFF.

Here is my main code: 

#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Swi.h>
#include <xdc/cfg/global.h>
#include <ti/sysbios/family/msp430/Power.h>
#include <cc430f6137.h>

uint16_t voltage;

void initLeds(void)
{
P1DIR |= BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P2DIR |= BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P3DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P4DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P5DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7; // terminating unused pins
PCDIR = 0xFF;
P2OUT = 0xFF;
P3OUT = 0xFF;
P5OUT = 0xFF;
P1OUT = 0xFF;
P4OUT = 0xFF;
PCOUT = 0xFF;

P2SEL |= BIT0;

P4DIR |= BIT2 + BIT1;
P4OUT &= ~(BIT2 + BIT1);
}

void initADC() {/*
ADC12CTL0 = 0xF870;
ADC12CTL1 = 0x0200;
ADC12CTL2 = 0x00A0;
ADC12MCTL0 = 0x50;
ADC12IE |= 0x01;
ADC12CTL0 |= ADC12ENC;*/
ADC12CTL0 = ADC12SHT01 + ADC12SHT03 + ADC12REF2_5V + ADC12REFON + ADC12ON; // internal reference 2.5V

ADC12CTL1 = ADC12SHP; // single sequence

ADC12MCTL0 = ADC12SREF_1;

ADC12MCTL0 |= ADC12INCH_0; // channel = A0
ADC12IE = 0x01; // enable interrupts for channel 0
ADC12CTL0 |= ADC12ENC; //start AD-conversion
}

void adcReadMem() {
voltage = ADC12MEM0;
System_printf("%d\n", voltage);
System_flush();
if(voltage > 2048) {
P4OUT ^= BIT1; // pulse red
}
else {
P4OUT ^= BIT2; // pulse yellow
}

P1IFG = 0;
P1IE |= BIT0;
ADC12IFG = 0;
ADC12IE |= BIT0;
//ADC12MEM0 = 0;
//TA0CTL |= TAIE;
}

void timerISR() {
//P4OUT ^= BIT2;
//TA0CTL &= ~TAIE;
ADC12CTL0 |= ADC12SC;
}

void adcISR() {
ADC12IE &= ~BIT0;
System_printf("%d\n", ADC12MEM0);
System_flush();
Swi_post(adcSwi);
}

Int main(void)
{
initLeds();
initADC();

BIOS_start();
}

Here is my config file:

var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
var Swi = xdc.useModule('ti.sysbios.knl.Swi');
var BIOS = xdc.useModule('ti.sysbios.BIOS');
var Power = xdc.useModule('ti.sysbios.family.msp430.Power');
var Timer = xdc.useModule('ti.sysbios.family.msp430.Timer');

var swi0Params = new Swi.Params();
swi0Params.instance.name = "adcSwi";
swi0Params.priority = 1;
Program.global.adcSwi = Swi.create("&adcReadMem", swi0Params);

Program.stack = 256;
BIOS.libType = BIOS.LibType_Custom;
BIOS.customCCOpts = "-vmspx --near_data=none --code_model=large --data_model=restricted -q --advice:power=1 --program_level_compile -o3 -g --optimize_with_debug";
BIOS.logsEnabled = false;
BIOS.assertsEnabled = false;
BIOS.taskEnabled = false;
BIOS.heapSize = 256;
Power.idle = true;
Power.idleMode = Power.LPM4;
var timer0Params = new Timer.Params();
timer0Params.instance.name = "timerHwi";
timer0Params.period = 1000000;
Program.global.timerHwi = Timer.create(-1, "&timerISR", timer0Params);
BIOS.clockEnabled = false;
BIOS.runtimeCreatesEnabled = false;
var hwi0Params = new Hwi.Params();
hwi0Params.instance.name = "adcHwi";
Program.global.adcHwi = Hwi.create(56, "&adcISR", hwi0Params);

**Attention** This is a public forum