I have simplified the code and now can get it to run. However, the output from the data buffer is really wrong.
when I should get a count timer I get a fixed value of 2.212E-314. This value prints no matter what buffer position I sample.
Also, I can only run my buffer loop to buf[65] instead of [120]. The program will not run and locks up. Any ideas? I need to buffer a string of 113 bytes, write the string to an SD card and then pull out selected ones to print to an LCD.
here is my current code.
//Code Designed to display run-time variables from a Megasquirt Fuel Injection controller.
//This is the base code to load variables and print to LCD.
#include "mbed.h"
#include "TextLCD.h"
Serial usb(USBTX, USBRX); //define USB connection pins
Serial megasquirt(p28, p27); //define serial commection pins
DigitalOut usb_activity(LED1); //define USB activity
DigitalOut megasquirt_activity(LED2); //define Megasquirt activity
unsigned char tmp_data[16];
unsigned char buf[120];
char buffer[120];
int tmp;
int AFR;
unsigned char data_out;
int i;
/*LCD 2x20 parallel code pin assignment*/
TextLCD lcd(p21, p22, p23, p24, p25, p26, p30, 20, 2); // (rs, rw, e, d0, d1, d2, d3, n_column, n_rows)
//enter main loop
int main() {
megasquirt.baud(115200); //define MEgasquirt serial speed
usb.baud(115200); //define USB connection speed
// unsigned char tmp;
// unsigned char data_in;
megasquirt_activity = 1;
while (1) {
lcd.locate(0,0); //Set LCD location
lcd.printf("AFR="); //text label on LCD
usb.printf("AFR="); //text label on LCD
if (megasquirt_activity = 1) {
//poll serial device for data stream (a,0,6) to (request, return, confirm)
megasquirt.putc(97);//send 97 for run parameters, 83 for board revision, 81 code for revision number
wait(0.005); //wiat for response
megasquirt.putc(0);
wait(0.005);
megasquirt.putc(6);
wait(0.005);
/////////////Insert buffer code here
//Data_out should be a buffer. I need 120 bytes
//need to know address of buffer
//buf = data_out; //test code for data buffer
for ( int i=0; i < 10; i++ ) {
buf[i] = megasquirt.getc();
//usb.putc(buf[29]);
//lcd.putc(buf[29]);
AFR = buffer[1]; //changed to count timer
lcd.locate(5,0);
lcd.printf("%E" ,AFR);
usb.printf("%E" ,AFR);
}
}
else {
lcd.printf("no connection");
usb.printf("no connection");
}
}
}
//exit main loop
Does anyone have example code to setup the internal databuffer and then write to it? I have searched the site and not yet found anything.
My application polls a serial device that returns a string of 120 bytes. These bytes need to be replced in a buffer. Additional bytes will be added to the buffer before interpretation and datalogging.
Communication to the serial device is working properly. .
Thanks.