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.

ADC values to UART

Hello,

I am trying to send the value of my ADC to the computer with UART0 (PA1). 

Can someone tell me the steps for doing that?

Here is what exactly I would like to do:

-acquire ADC value ( this I know how to do)

-send the 4 MSB with the UART

-send the other 8 LSB with the UART

Should I do all this in my AD0SS3_handler? 

Do i have to use sprintf()? If yes, would it be like this: sprintf(str,"%d\t%d\n",MSB_value,LSB_value); where msb and lsb are int

if I use sprintf do i have to use UARTCharPut ?? and where should I use it? In my main or in a handler?

Thank you in advance,

Étienne

P.S. I already configured everything right uart, adc,gpios,etc... I just need a little help to continue with the uart!:)

  • You may wish to add these 3 points to your consideration:

    • the ADC stores its value in "none too human friendly, binary format"
    • your receiving UART device may not be "happy" receiving such binary data
    • realizing "accurate" 12 bit data proves quite a challenge for most all such class MCUs

    Has your, "already configured everything right" report included the (necessary) binary to decimal conversions?

    Would not (starting) with the 8 msb prove adequate?    (most always does for my small, tech firm - and greatly speeds/simplifies your task...)

    We've long been taught that interrupt service should be, "short/sweet" - thus burdening the ADC handler w/slow UART traffic is not recommended.   Instead - the ADC's interrupt may "set a flag" - which is recognized & responded to w/in main.

    Your question list continues - yet I believe there's sufficient detail here to get you going - and not "muddy the waters" w/UART details.   (covered very nicely - elsewhere...)

  • Hi,

    Well I will tell you, this is easier than you think.

    Send bits? Well you will, but you won't send the 12bits, there's no need!

    sprintf? Well you could, but then you need to create a function to send each char (each byte). This would right away throw off the option of sending an integer is binary - instead it would convert each digit (in base 10 format) to a char.

    You should try to use UARTstdio. You can more easily setup the UART but even more useful, you have a function that works pretty much like printf in C. If I am not mistaken there's an example in the Tivaware package. (really can't remember if it is with UARTstdio). You can check if this is useful too sites.google.com/.../basic-use-of-uart-stdio

    Now about sending the data itself. You are sending chars. If you use a integer to hold and ADC value and you try to read it with debug it will show a number like 3596. Not the binary format (although it can). Now why not simply send that over to the computer with the printf like function? It would be much easier: "printf(%d %d,MSB_value,LSB_value);" wouldn't it?

    Now before I continue any explanation - what do you want to do with those values. If you want to read them on a serial monitor like putty this is the way to go - send each digit as a char, not send the binary 12bits that represent your integer values, that would result in gibberish!
    Maybe between ICs or other MCU it could be useful sending individual bits instead of chars

    (now of course when I say chars I know that it's 8bits that are being sent, I just mean that there's sending an actual char then there's sending bits that should not be seen as a character representation from the ASCII code)





    All that said, maybe this will help sites.google.com/.../internal-temperature-sensor