LPCxpresso  ADC + UART sample

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPCxpresso  ADC + UART sample

527 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Novato on Wed May 26 06:36:34 MST 2010
Hello  friends of the forum, sorry but my English is very basic, I'm new  programming in C and need to know if someone did some practice with  LPCxpresso 1343, I'm  using LPCXpresso v3.2 by Code Red .. my problem is how I can use the ADC sampling and take  that data and send it by UART. Someone I  can post some easy to understand example to work on it because the  examples that are used interruption and are very difficult to understand  for me. Thanks

Original Attachment has been moved to: 1100419_bitband.txt.zip

0 Kudos
5 Replies

375 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by renan on Thu May 27 12:49:04 MST 2010
Ok.

We are almost neighbors (hehhe), do you live near the border with Rio Grande do Sul (Brazil)? :)
0 Kudos

375 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Novato on Thu May 27 12:03:40 MST 2010
Thanks Renan friend, I  will continue doing some tests and then commented on the forum.Thanks
0 Kudos

375 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by renan on Thu May 27 04:18:42 MST 2010

Quote: Novato

    UARTInit(115200);       //---------------------------------here ?
    UARTSendString((uint8_t*)"BNC - OLED\r\n");    //------here?

   



UART seems ok, if your #include "uart.h" is the same from Code Red.
Why did you cast to (uint8_t*), just
UARTSendString("BNC - OLED\r\n"); 

should work fine.

I don't know about ADC, I haven't used so I can't help you.

Renan
0 Kudos

375 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Novato on Wed May 26 12:19:59 MST 2010
Thanks  for replying, i upgrade to 3.3.4.201004081702. posting an example to help me, I just need to show me what  would be the basic functions to read the ADC and write it into the  UART. Thanks


code:

/*****************************************************************************
*   Value read from BNC is written to the OLED display (nothing graphical
*   yet only value).
*
*   Copyright(C) 2009, Embedded Artists AB
*   All rights reserved.
*
******************************************************************************/


#include "type.h"
#include "uart.h"
#include "stdio.h"
#include "timer32.h"
#include "i2c.h"
#include "gpio.h"
#include "ssp.h"
#include "adc.h"


#include "oled.h"


static uint8_t buf[10];

static void intToString(int value, uint8_t* pBuf, uint32_t len, uint32_t base)
{
    static const char* pAscii = "0123456789abcdefghijklmnopqrstuvwxyz";
    int pos = 0;
    int tmpValue = value;

    // the buffer must not be null and at least have a length of 2 to handle one
    // digit and null-terminator
    if (pBuf == NULL || len < 2)
    {
        return;
    }

    // a valid base cannot be less than 2 or larger than 36
    // a base value of 2 means binary representation. A value of 1 would mean only zeros
    // a base larger than 36 can only be used if a larger alphabet were used.
    if (base < 2 || base > 36)
    {
        return;
    }

    // negative value
    if (value < 0)
    {
        tmpValue = -tmpValue;
        value    = -value;
        pBuf[pos++] = '-';
    }

    // calculate the required length of the buffer
    do {
        pos++;
        tmpValue /= base;
    } while(tmpValue > 0);


    if (pos > len)
    {
        // the len parameter is invalid.
        return;
    }

    pBuf[pos] = '\0';

    do {
        pBuf[--pos] = pAscii[value % base];
        value /= base;
    } while(value > 0);

    return;
}


int main (void)
{
    uint32_t val  = 0;

    GPIOInit();
    init_timer32(0, 10);

    UARTInit(115200);       //---------------------------------here ?
    UARTSendString((uint8_t*)"BNC - OLED\r\n");    //------here?

    I2CInit( (uint32_t)I2CMASTER, 0 );
    SSPInit();
    ADCInit( ADC_CLK );   //--------------------------------here ?

    oled_init();

    oled_clearScreen(OLED_COLOR_WHITE);

    oled_putString(1,1,  (uint8_t*)"BNC: ", OLED_COLOR_BLACK, OLED_COLOR_WHITE);


    while(1) {

        /* analog input connected to BNC */
        val = ADCRead(5); // ----------------------------------here ??

        /* output values to OLED display */

        intToString(val, buf, 10, 10);
        oled_fillRect((1+6*6),1, 80, 8, OLED_COLOR_WHITE);
        oled_putString((1+6*6),1, buf, OLED_COLOR_BLACK, OLED_COLOR_WHITE);


        /* delay */
        delay32Ms(0, 200);
    }

}
0 Kudos

375 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by renan on Wed May 26 07:39:12 MST 2010
First, I think it is better if you update your LPCXpresso to the latest version 3.3.4.

Renan
0 Kudos