Part Number: MSP430FR4133
Tool/software: Code Composer Studio
Hi all,
So bottom line, I'm incredibly confused. I've been stumped by the same issue for a week now and need some help. I am using the MSP430fr4133 and attempting to read from any of the external ADC pins. I have some previous experience with some other microcontrollers so I'm not completely new to this. I have some key questions. As far as hardware, I have attempted reading pins with a constant voltage source, or directly tied to ground and instead and I am reading some count number that is completely independent, however, not independent of temperature, if you were interested.
1. The sampling and holding time affects the read counts, one above 32 clock cycles, the fluctuations reduce from plus/minus 20 to plus/minus 2.
2. Changing the reference voltage has no effect on this floating number.
3. Changing between 8-10-12 bit conversions has no effect on the floating number.
4. Confirm that when ADCSHP is set to 0, ADCSC starts conversions. If I set it to 0, then the entire conversion doesn't work. I have no timers setup so it wouldn't make sense with it being set to 1, however, it only conducts conversions when the ADCSHP is 1.
#include <msp430.h>
#include <string.h>
#include <stdio.h>
#include <driverlib.h
void SYSTEMinit();
void UARTinit();
void ADCinit();
int writeUART(char* sentence);
int analog (int channel);
int tempConvert(int counts);
int main(void)
{
char buffer[30];
SYSTEMinit();
UARTinit();
ADCinit();
int temp = 0;
while(1)
{
sprintf(buffer, "ADC 6 %d \n\r", analog(6);
writeUART(buffer);
_delay_cycles(4000000);
}
}
void SYSTEMinit()
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure GPIO
//Init_GPIO();
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate 1previously configured port settings
//__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_3; // Set DCO = 8MHz
CSCTL2 = FLLD_0 + 243; // DCODIV = 8MHz
CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32kHz) as ACLK source, ACLK = 32768Hz
// default DCODIV as MCLK and SMCLK source
}
void UARTinit()
{
//STEP 1 Set UCSWRST Bit
UCA0CTLW0 |= UCSWRST; //Allows UART to be configured
//STEP 2 Initialize all relevant Registers
UCA0CTLW0 |= UCSSEL__SMCLK; //Choses SMCLK as clock source for UART
UCA0BR0 = 52; // 8000000/16/9600 CORRECT 9600 BAUD RATE
//UCA0BR1 = 0x00;
UCA0MCTLW = 0x4900 | UCOS16 | UCBRF_1;
//STEP 3 Configure Ports
P1SEL0 |= BIT0 + BIT1; // set 2-UART pin as Primary non I/O function
//STEP 4 SEt UCSWRST Bit
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
//STEP 5 ENABLE INTERUPTS
__enable_interrupt( );
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
_delay_cycles(4000000);
writeUART("start");
}
void ADCinit()
{
ADCCTL0 |= ADCSHT_3 + ADCON; // ADCON, S&H=32 ADC clks
ADCMCTL0 &=~ ADCCONSEQ0 + ADCCONSEQ1; //Sets single conversion single channel mode
ADCMCTL0 |= ADCSREF0; //Sets top of scale to VREF and bottom to ground
//ADCCTL1 |= ADCSHP;
ADCCTL1 &=~ ADCSSEL0 + ADCSSEL1; // ADCCLK = MODOSC; sampling timer
ADCCTL1 &=~ ADCSHP; //Initialized ADC conversation after ADCS bit not a timer
ADCCTL2 |= ADCRES_1; //0 gives 8 bit, 1 gives 10 bit, 2 gives 12 bit.
SYSCFG2 |= ADCPCTL6; //Enables ADC inputs. This is critical for all external ports. Temp sensor cannot be configured
//P1SEL0 |= BIT3;
//DECLARE INPUT PINS WHEN WE HAVE THEM. Temp sensor doesnt need to be declared
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers. REQUIRED FOR TEMPERATURE SENSOR
PMMCTL2 |= TSENSOREN + INTREFEN; // Enable internal reference
__delay_cycles(400); // Delay for reference settling
ADCCTL0 |= ADCENC; //Enables ADC. Main bits above can no longer be edited
}
int analog (int channel)
{
if (channel == 2)
{
ADCMCTL0 = 0x02;
}
if (channel == 3)
{
ADCMCTL0 = 0x03;
}
if (channel == 4)
{
ADCMCTL0 = 0x04;
}
if (channel == 5)
{
ADCMCTL0 = 0x05;
}
if (channel == 6)
{
ADCMCTL0 = 0x06;
}
if (channel == 7)
{
ADCMCTL0 = 0x07;
}
if (channel == 12)
{
ADCMCTL0 = ADCINCH_12;
}
ADCCTL0 |= ADCSC; // starts ADC conversion
while(ADCCTL1 & ADCBUSY);
return ADCMEM0;
}
int writeUART(char* sentence)
{
int i;
for (i = 0; i < strlen(sentence); i++) {
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = sentence[i];
}
return i;
}
Any help would be greatly appreciated. Thank you for your time.
Austin
