How store the data into RAM with ID for each input?

11 Mar 2011

In this program I read the 6 analog inputs and send this data to urat for every 2 min. But I want to store this data into RAM with each ID for each input.After this only i want to send this through uart. How to frame this? could you help me?

  1. include <mbed.h> AnalogIn ain_UseA(p15); AnalogIn ain_UseB(p16); AnalogIn ain_UseC(p17); AnalogIn ain_UseD(p18); AnalogIn ain_UseE(p19); AnalogIn ain_UseF(p20); BusOut myled1(LED1); Ticker ADC; float vdiv = (3.3 / 65535); float avg[6] = {0,0,0,0,0,0}; void read_ADC();

Serial uart(p28, p27); int main() {

uart.baud(9600); uart.format(8,Serial::None,1); ADC.attach(&read_ADC, 20.0); float avg[6];

while( 1 ){ } } void read_ADC() { avg[0] = (avg[0]+(float)ain_UseA.read_u16()* vdiv)/2; avg[1] = (avg[1]+(float)ain_UseB.read_u16()* vdiv)/2; avg[2] = (avg[2]+(float)ain_UseC.read_u16()* vdiv)/2; avg[3] = (avg[3]+(float)ain_UseD.read_u16()* vdiv)/2; avg[4] = (avg[4]+(float)ain_UseE.read_u16()* vdiv)/2; avg[5] = (avg[5]+(float)ain_UseF.read_u16()* vdiv)/2; uart.printf("AI1:%5.3f\n AI2:%5.3f\n AI3:%5.3f\n AI4:%5.3f\n AI5:%5.3f\n AI6:%5.3f\r\n ", avg[0],avg[1],avg[2],avg[3],avg[4],avg[5]); }

11 Mar 2011

Please use <<code>> ... <</code>> tags when including code as it formats easier to read.

The example below is the same as yours but with the printf() moved out of the interrupt into your main loop. This is a much better (and safer) way to use printf() (see this link for more details).

However, I'm not entirely sure I understand your question, if there is one. Is this of help?

#include <mbed.h> 

AnalogIn ain_UseA(p15); 
AnalogIn ain_UseB(p16); 
AnalogIn ain_UseC(p17); 
AnalogIn ain_UseD(p18); 
AnalogIn ain_UseE(p19); 
AnalogIn ain_UseF(p20); 
BusOut myled1(LED1); 
Ticker ADC; 
float vdiv = (3.3 / 65535); 
float avg[6] = {0,0,0,0,0,0}; 
Serial uart(p28, p27); 

void read_ADC(void); 

volatile bool data_ready;

int main() {
    uart.baud(9600); 
    uart.format(8,Serial::None,1); 
    data_ready = false;
    ADC.attach(&read_ADC, 20.0); 
    float avg[6];

    while( 1 ) { 
        if(data_ready) {
            data_ready = false;
            uart.printf("AI1:%5.3f\n AI2:%5.3f\n AI3:%5.3f\n AI4:%5.3f\n AI5:%5.3f\n AI6:%5.3f\r\n ", avg[0],avg[1],avg[2],avg[3],avg[4],avg[5]); 
        }
    } 
} 

void read_ADC(void) { 
    avg[0] = (avg[0]+(float)ain_UseA.read_u16()* vdiv)/2; 
    avg[1] = (avg[1]+(float)ain_UseB.read_u16()* vdiv)/2; 
    avg[2] = (avg[2]+(float)ain_UseC.read_u16()* vdiv)/2; 
    avg[3] = (avg[3]+(float)ain_UseD.read_u16()* vdiv)/2; 
    avg[4] = (avg[4]+(float)ain_UseE.read_u16()* vdiv)/2; 
    avg[5] = (avg[5]+(float)ain_UseF.read_u16()* vdiv)/2; 
    data_ready = true;
}
11 Mar 2011

I interfaced LPC1768 mbed kit with XDM2510 RFmodule through UART.I need to read the 6 analog inputs for every 2 min and store it into RAM and send to XDM2510 through uart.

I want to distinguish the 6 analog inputs while storing.(sensor1..... sensor6). Is anything i want to do in printf?