![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ADXL345 test on L476
Diff: main.cpp
- Revision:
- 1:2098adebc6da
- Parent:
- 0:a0f7c6807a3a
- Child:
- 2:2a57e2a50796
diff -r a0f7c6807a3a -r 2098adebc6da main.cpp --- a/main.cpp Thu Nov 30 20:01:44 2017 +0000 +++ b/main.cpp Sat Dec 16 11:22:15 2017 +0000 @@ -6,11 +6,24 @@ int x, y, z; -Serial mySerial(SERIAL_TX, SERIAL_RX, 9600); // tx, rx +volatile char input_buffer[90]; // store everything received +volatile char message_buffer[90]; // store message +volatile char input_buffer_counter = 0; +volatile char message_counter = 0; +volatile char input_flag = false; + +volatile char latitude[13] = {' ','1',' ','3',' ',' ',' ',' ',' ',' ',' ',' ',' '}; +volatile char longtitude[13] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};; +volatile char coorFlag = 0; + + +Serial mySerial(SERIAL_TX, SERIAL_RX, 9600); // tx, rx +Serial gpsSerial(A0, A1, 9600); // tx, rx I2C i2cAcc(I2C_SDA, I2C_SCL); void ADXL_ISR(); +void rxHandler(); int main() { @@ -58,6 +71,8 @@ mySerial.printf("SparkFun ADXL345 Accelerometer Hook Up Guide Example\n"); + gpsSerial.attach(rxHandler); + while(1) { @@ -71,10 +86,34 @@ //mySerial.printf("X: %i\nY: %i\nZ: %i\n================\n", x, y, z); //wait(2); - ADXL_ISR(); + //ADXL_ISR(); // You may also choose to avoid using interrupts and simply run the functions within ADXL_ISR(); // and place it within the loop instead. // This may come in handy when it doesn't matter when the action occurs. + /* + if(input_flag) // if message received + { + // check type of message and either send it directly, or convert to another type and send + // + // GGA input, send directly ============================================================= + if(input_buffer[1] == 'G') + { + for(char i=0; i<message_counter; i++) // copy message stored to output_buffer; + message_buffer[i] = input_buffer[i]; + + message_counter = input_buffer_counter; // set output pointer/counter value to input message counter value + } + } + */ + + if(coorFlag) // show coordinates + { + mySerial.printf("latitude: %s\n", latitude); + mySerial.printf("longtitude: %s\n", longtitude); + + coorFlag = 0; + } + } } @@ -119,3 +158,83 @@ } } + +// RX interrupt handler +// stores everything into input_buffer +void rxHandler() +{ + char tmp; + + do + { + tmp = gpsSerial.getc(); // read serial data + + if(tmp == '$') // if message start character( every nmea message starts with $) + { + input_buffer_counter = 0; // reset inut buffer counter + return; + } + + if(tmp == '*') // if end of message( every nmea message ends with *+CRC) + { + if(input_buffer[3] == 'L') // if nmea string type is GPGLL + { + int t = 0; + int lat = 0; + int lon = 0; + + for(int i=0; i<13; i++) // clear latitude and longtitude + { + latitude[lat++] = ' '; + longtitude[lon++] = ' '; + } + + while(input_buffer[t] != ',') // find coma after GPGLL + t++; // t points coma after GPGLL + + t++; // set to to first latitude character + + + lat = 0; + + while(input_buffer[t] != ',') // copy latitude value + { + latitude[lat] = input_buffer[t]; + lat++; + t++; // t points coma after latitude + } + latitude[lat] = input_buffer[t]; // copy coma + t++; + latitude[lat] = input_buffer[t]; // copy N or S direction + t++; + + t++; // set t to first character of longtitude + + + lon = 0; + + while(input_buffer[t] != ',') // copy longtitude value + { + longtitude[lon] = input_buffer[t]; + lon++; + t++; // t points coma after longtitude + } + longtitude[lon] = input_buffer[t]; // copy coma + t++; + longtitude[lon] = input_buffer[t]; // copy W or E direction + + coorFlag = 1; + + gpsSerial.printf("message: %s", input_buffer); + + } + return; + } + + input_buffer[input_buffer_counter] = tmp; + input_buffer_counter++; + } + while(gpsSerial.readable()); +} + +