Apologies for the confusion. The code I provided earlier was based on assumptions about the microcontroller and header file being used. To address the error you encountered, please make sure you have included the appropriate header file that defines the ADC registers.
Here’s an updated version of the init_adc14 function assuming you are using an MSP432P401R microcontroller with “msp432p401r.h” header:
#include <msp432p401r.h>
void init_adc14(void) {
// Select HSMCLK as clock source for ADC14CLK, predividing by 1 and dividing by 2
ADC14CTL0 &= ~(ADC14_CTL0_ON | ADC14_CTL0_SHP | ADC14_CTL0_SHS_3 | ADC14_CTL0_CONSEQ_3 |
ADC14_CTL0_MSC);
ADC14CTL0 |= (ADC14_CTL0_SSEL__HSMCLK | ADC14_CTL0_DIV__1 | ADC14_CTL0_PDIV__2);
// Set conversion address start to MEM[0]
ADC14CTL1 &= ~ADC_STARTADD_MASK;
ADC14CTL1 |= (ADC_MEM0 & 0x000F);
// Select Pulse Sample Mode, single-channel single-conversion mode
ADC12CTL1 |= (ADC12SHP);
// Set sampling period to 96 clock cycles for MEM[0]
ADC12MCTL[MEM[0]] = (96 - 32) << 8;
// Set resolution to 16 bits
ADC12BCTL[17] |= BIT7; // Set resolution to 16 bits
// Turn on ADC, leave ENC and other bits of CTL register to default value (disabled)
ADC12CTL00 |= (BIT15);
}
Please ensure that you have included the correct header file for your microcontroller and adjust the register names if necessary.
内容由零声教学AI助手提供,问题来源于学员提问




