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.

MSP432P401R Multiple channel conversion and sending through UART no output in the serial monitor

Hi all! I am trying to read analog signal from 3 pins and send it through UART, however nothing is being printed in the serial monitor. Could you help me and maybe point a mistake in my code?


#include "msp.h"
#include <stdint.h>


int main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | // Stop watchdog timer
WDT_A_CTL_HOLD;

// Configure GPIO
P5->SEL1 |= BIT5 | BIT4 | BIT3; // Enable A/D channel A0-A3
P5->SEL0 |= BIT5 | BIT4 | BIT3;

// Enable global interrupt
__enable_irq();

NVIC->ISER[0] = 1 << ((ADC14_IRQn) & 31);// Enable ADC interrupt in NVIC module

// Turn on ADC14, extend sampling time to avoid overflow of results
ADC14->CTL0 = ADC14_CTL0_ON |
ADC14_CTL0_MSC |
ADC14_CTL0_SHT0__192 |
ADC14_CTL0_SHP |
ADC14_CTL0_CONSEQ_3;

ADC14->MCTL[0] = ADC14_MCTLN_INCH_0; // ref+=AVcc, channel = A0
ADC14->MCTL[1] = ADC14_MCTLN_INCH_1; // ref+=AVcc, channel = A1
ADC14->MCTL[2] = ADC14_MCTLN_INCH_2| // ref+=AVcc, channel = A2, end seq.
ADC14_MCTLN_EOS;

ADC14->IER0 = ADC14_IER0_IE3; // Enable ADC14IFG.3

//configure UART
CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
CS->CTL0 = 0; // Reset tuning parameters
CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
CS->CTL1 = CS_CTL1_SELA_2 | // Select ACLK = REFO
CS_CTL1_SELS_3 | // SMCLK = DCO
CS_CTL1_SELM_3; // MCLK = DCO
CS->KEY = 0; // Lock CS module from unintended accesses

// Configure UART pins
P1->SEL0 |= BIT2 | BIT3; // set 2-UART pin as secondary function

// Configure UART
EUSCI_A0->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
EUSCI_A0->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset
EUSCI_B_CTLW0_SSEL__SMCLK; // Configure eUSCI clock source for SMCLK
EUSCI_A0->BRW = 78; // 12000000/16/9600
EUSCI_A0->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |
EUSCI_A_MCTLW_OS16;

EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI

SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; // Wake up on exit from ISR

// Ensures SLEEPONEXIT takes effect immediately
__DSB();

while(1)
{
// Start conversion-software trigger
ADC14->CTL0 |= ADC14_CTL0_ENC |
ADC14_CTL0_SC;
__sleep();
__no_operation(); // For debugger
}
}

// ADC14 interrupt service routine
void ADC14_IRQHandler(void)
{
if (ADC14->IFGR0 & ADC14_IFGR0_IFG3)
{
UCA0TXBUF = ADC14->MEM[0];
UCA0TXBUF = ' ';
UCA0TXBUF = ADC14->MEM[1];
UCA0TXBUF = ' ';
UCA0TXBUF = ADC14->MEM[2];
UCA0TXBUF = '\n';


}
}

  • You probably need some delays between your transmits, the MCU is much much faster than the UART.

    I am not sure what character "''" is, what are you trying to send?

    Depending on your terminal software, it might not print anything if you send it a random character like the digital output of the ADC.

  • Also:

    > ADC14->IER0 = ADC14_IER0_IE3; // Enable ADC14IFG.3

    This will only interrupt when MEM[3] is loaded, but that won't happen since EOS is set in MCTL[2]. Try instead:

    > ADC14->IER0 = ADC14_IER0_IE2; // Enable ADC14IFG.2

  • thank you for spotting that. However I am still getting some weird behaviour. When I changed it to:

    ADC14->MCTL[0] = ADC14_MCTLN_INCH_0; // ref+=AVcc, channel = A0
    ADC14->MCTL[1] = ADC14_MCTLN_INCH_1; // ref+=AVcc, channel = A1
    ADC14->MCTL[2] = ADC14_MCTLN_INCH_2 | ADC14_MCTLN_EOS;

    ADC14->IER0 = ADC14_IER0_IE2; // Enable ADC14IFG.2

    it doesn't work, however it works when:

    ADC14->MCTL[0] = ADC14_MCTLN_INCH_0; // ref+=AVcc, channel = A0
    ADC14->MCTL[1] = ADC14_MCTLN_INCH_1; // ref+=AVcc, channel = A1
    ADC14->MCTL[2] = ADC14_MCTLN_INCH_2;
    ADC14->MCTL[3] = ADC14_MCTLN_EOS;

    ADC14->IER0 = ADC14_IER0_IE3; // Enable ADC14IFG.3

    Could you help me understand that? I don't want to used 4 channels as it decreases my sampling frequency.

  • Works! I forgot to change the if statement in the interrupt function to ADC14_IFGR0_IFG2. Thank you so much! 

**Attention** This is a public forum