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.

MSP430fr4133 ADC 10 bit single channel single conversion



Hello,

I would like some help with the code to get ADC single conversion. Please tell me minimum lines of code needed to do this, with respect to the following.

1. Is it required that Pin P8.0 which corresponds to the channel A8 (Which I am applying my voltage to digitize) of ADC needs to be configured to other that a normal I/O (using PxSEL registers)?

2. Overall single channel single conversion using the conversion complete interrupt, and interrupt service routine.

Thanks.

  • Hi Rohan,

    We have code examples available for Single-Channel Single-Conversion using the ADC. You can find these examples here: dev.ti.com/.../ This particular code example is sampling from the A1 pin.

    If you want to using P8.0 for channel A8, please refer for page 66 in the datasheet: http://www.ti.com/lit/ds/symlink/msp430fr4133.pdf As you can see in the below table you have to set the ADCPCTL8 to 1 in order to configure P8.0 as A8.

    Best Regards,

    Akash Patel

  • Hello Akash,

    Thanks for your reply. That helped me set up my ADC. However the ISR used in that example file is way different from the ISR i wrote for my UART.

    ADC ISR:
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC_VECTOR
    __interrupt void ADC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
    {
    case ADCIV_NONE:
    break;
    case ADCIV_ADCOVIFG:
    break;
    case ADCIV_ADCTOVIFG:
    break;
    case ADCIV_ADCHIIFG:
    break;
    case ADCIV_ADCLOIFG:
    break;
    case ADCIV_ADCINIFG:
    break;
    case ADCIV_ADCIFG:
    ADCResult = ADCMEM0;
    break;
    default:
    break;
    }
    }

    Whereas UART ISR:
    #pragma vector = USCI_A0_VECTOR

    __interrupt void USCI_A0_ISR(void){

    switch(__even_in_range(UCA0IV,18)){

    case 0x00:
    break;

    case 0x02:
    enqueue(&REC_q,(UCA0RXBUF & 0x00FF));
    break;

    case 0x04:
    break;

    case 0x08:
    break;

    default:
    break;
    }
    }

    Can you explain whats that extra stuff in ADC ISR? And should I have the same in my UART ISR?

    Thanks,
    Rohan L
  • Hi Rohan,

    What extra stuff in the ADC ISR are you referring to?

    The example code is in LPM0 waiting for an ADC interrupt. When this ADC interrupt occurs, we are interested in the case when ADCIV_ADCIFG is set (meaning that ADC conversion is completed) in order to copy the contents of ADCMEM0 to our variable ADCResult.

    Regards,
    Akash Patel
  • Hi,
    By extra stuff, I mean the following, which is not there in the UART ISR that I wrote. However both ISRs work fine.

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC_VECTOR
    __interrupt void ADC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
    #else
    #error Compiler not supported!
    #endif

    Let me know.

    Thanks,
    Rohan L
  • Hi Rohan,

    That has to do with the compiler being used for the example code. As this is example code being provided, it can work with the TI compiler, the IAR compiler, and the GNU compiler. Depending on which compiler is being used, there is a different way of initializing the interrupt vector. If you are using the TI compiler or the IAR compiler then you want to initialize this like so:

    #pragma vector=ADC_VECTOR
    __interrupt void ADC_ISR(void)

    It looks like you have it set up similarly in your UART ISR so that is good. You don't have to add the extra code unless you plan on having your code run with other compilers.

    As you can see in the above snippet, lines 114-118 are grayed out as they are not relevant because I am using the TI compiler for this code.

    Regards,

    Akash Patel

  • Hi Akash,
    Thanks for the input.

    I have one more question. I converted the ADC result into a float by calculations.
    Now I want to convert that float to a string to send it over the UART.

    I tried using sprintf() (print a float to a string), but it gives a warning for implicit declaration of sprintf().
    Does sprintf() work with stdlib.h?
    PS: I am using CCS.

    Thanks,
    Rohan L
  • Hi Rohan,

    Maybe try using #include <stdio.h> to see if that works? That appears to be what they use here: www.cplusplus.com/.../ and I don't get that same warning when trying to build my code in CCS using that.

    Regards,
    Akash Patel

**Attention** This is a public forum