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.

MSP432WARE: ADC14 single _differential measurements + Uart

Part Number: MSP432WARE


Dear All, 

I am new on  MSP432 and embedded systems. I will start to new project about  differantial voltage measurement and i will visualise on Labview but firstly,

I tried to combine two example code from MSPWARE.

First one is ADC14 single differential 2's complement code.

Second one is 12 Mhz Uart Echo  code.

1.This two code from driverlib examples and i enable and define EUSCIA0_IRQHandler and ADC14_IRQHandler from startup file.

2. I copied to uart configuration enabling and interrupt settings  to ADC14 code from Echo code.

I want to see ''result'' value in my terminal. 

How can i combine this parts. 

Thank you.

/* This interrupt happens every time a conversion has completed. Since the FPU
* is enabled in stacking mode, we are able to use the FPU safely to perform
* efficient floating point arithmetic.*/


void ADC14_IRQHandler(void)
{
uint64_t status;

status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status);

if(status & ADC_INT0)
{
adcResult = convertToFloat(MAP_ADC14_getResult(ADC_MEM0));
}

}




/* Converts the ADC result (14-bit) to a float with respect to a 3.3v reference
*/


static float convertToFloat(uint16_t result)
{
int32_t temp;

if(0x8000 & result)
{
temp = (result >> 2) | 0xFFFFC000;
return ((temp * 3.3f) / 8191);
}
else
return ((result >> 2)*3.3f) / 8191;
}






/* EUSCI A0 UART ISR - Echoes data back to PC host */


void EUSCIA0_IRQHandler(void)
{
uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);

MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);

if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
{
MAP_UART_transmitData(EUSCI_A0_BASE, MAP_UART_receiveData(EUSCI_A0_BASE));
}

}

  • Hello,

    There are a couple of ways to address this depending upon the sampling rate of the ADC.  You could simply measure a sample and with the interrupt write to the UART TX buffer, this will limit your sample rate to how quickly you can transmit.  You could use the DMA in a scatter-gather mode to try and write the information to the UART without CPU overhead but you will still be limited by the UART frequency.

    Please note that the UART is limited to 7MBaud.

    As a starting point, I would simply move the transmit API into the ADC interrupt service routine.  You will need to send two bytes since the result is 14 bits wide.

    void ADC14_IRQHandler(void)
    {
    uint64_t status;
    uint16_t txByte; status = MAP_ADC14_getEnabledInterruptStatus(); MAP_ADC14_clearInterruptFlag(status); if(status & ADC_INT0) { txByte = MAP_ADC14_getResult(ADC_MEM0);
    //wait for tx buffer to be ready
    while (!MAP_UART_getInterruptStatus(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG));
    MAP_UART_transmitData(EUSCI_A0_BASE,(uint8_t)txByte);
    txByte = txByte >> 8;
    //wait for tx buffer to be ready
    while (!MAP_UART_getInterruptStatus(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG));
    MAP_UART_transmitData(EUSCI_A0_BASE,(uint8_t)txByte);
    } }

    Regards,
    Chris

     

  • Thank you for the suggestions,

    The terminal shows some values now but If i return with ''result'', this code directly converts the voltage to a value between 2^0 and 2^14.
    Maybe It will be a stupid question but Which one should i choose for reading from uart for labview normal voltage value or bit value ? I need to research more and more.
  • In some cases it makes sense to send the raw values to the host (in your case labview), so that the microcontroller can go back to sleep sooner. If power is not a convern, then I do not think it will matter whether you do processing on the MSP or in the host PC.

    Chris

**Attention** This is a public forum