Hi,
So I'm looking to automate an ADC reading upon the device's startup by inserting some code into the DigitalSensorInit from the SensorHub_Project CCS project (there's a few things that shouldn't be looped through, but I just wanna get it working before going after that :p ). Essentially, I want to sample ADC0 every second and store it into FRAM (adc_register is a 64 element 16-bit array, and read_time is 64). I've been trying to test this by connecting ADC0 to a small DC source, and no matter what value I use (I've tried 0-0.7V), the data I read back from the FRAM for each sample is 1FF0. I thought the setup below would suffice, but something else is definitely wrong. What would be an issue with the setup below?
Thanks!
void DigitalSensorInit() { //ROM sets P1OUT = 0x0F, this then consumes some current P1OUT = 0x00; // needed to reduce power consumption on RF430FRL152H EVM, since P1.3 is connected to a 2.2K Ohm resistor on the EVM to ground P1DIR &= ~MASTER_SLAVE_SELECT; // check if digital sensor mode is selected if (P1IN & MASTER_SLAVE_SELECT) { //P1DIR &= ~MASTER_SLAVE_SELECT; //host controller mode selected, exit return; } /* For custom digital sensor initialization, keep the previous code as is and change the following as needed.*/ // Configure P1.0 and P1.1 pins for I2C mode PORT_I2C_SEL0 |= SCL + SDA; PORT_I2C_SEL1 &= ~(SCL + SDA); // configure eUSCI for I2C UCB0CTL1 |= UCSWRST; // Software reset enabled UCB0CTLW0 |= UCMODE_3 + UCMST + UCSYNC + UCTR; // I2C mode, Master mode, sync, transmitter UCB0CTLW0 |= UCSSEL_2; // select SMCLK at 2MHz UCB0BRW = 20; // 2Mhz / 20 = 100kHz UCB0I2CSA = 0x0048; // slave address of device UCB0CTL1 &= ~UCSWRST; // exit reset mode u08_t i; for (i = 0; i < read_time; i++){ SD14CTL0 |= SD14EN; SD14CTL0 |= SD14IE; SD14CTL0 |= VIRTGND; // use avss instead of svss SD14CTL0 |= SD14SGL; SD14CTL1 |= SD14INTDLY1; SD14CTL0 |= SD14SC; //Start conversion of ADC, enable ADC while( !(SD14CTL0_H & ADC_SD14IFG_8BIT) ); //wait for conversion to finish (for single conversion), ADC_SD14IFG_8BIT = 0x02 adc_register[i] = SD14MEM0; SD14CTL0 &= ~SD14SC; //Stop conversion SD14CTL0 &= ~SD14EN; //disable ADC __delay_cycles(2000000); } return; }