Trying to log data from UM6 sensor with GPS receiver LS20031. I have two problems: - I can't log to file at a fast rate (<0.5s) without data values freezing to a fixed value. Print to pc screen it works fine. Ideally I would do this with an interrupt (e.g. ticker) so that the time of each reading is a fixed interval - I removed this as I thought this was causing the problem. - I want to record GPS lat and long. I have setup the GPS ground speed so I know the sensor are communicating. So I possibly havent set the config file to correctly interpet these two signals.

Dependencies:   MODSERIAL mbed

Fork of UM6_IMU_AHRS_2012 by lhiggs CSUM

Committer:
njewin
Date:
Sat May 04 09:34:15 2013 +0000
Revision:
6:43029c69b9ac
Parent:
0:03c649c76388
publish version ; bugs need correcting for:; - logging to file at 10ms rate; - reading GPS lat and long data

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lhiggs 0:03c649c76388 1 #ifdef COMPILE_EXAMPLE_CODE_MODSERIAL_MODDMA
lhiggs 0:03c649c76388 2
lhiggs 0:03c649c76388 3 /*
lhiggs 0:03c649c76388 4 * To run this test program, link p9 to p10 so the Serial loops
lhiggs 0:03c649c76388 5 * back and receives characters it sends.
lhiggs 0:03c649c76388 6 */
lhiggs 0:03c649c76388 7
lhiggs 0:03c649c76388 8 #include "mbed.h"
lhiggs 0:03c649c76388 9
lhiggs 0:03c649c76388 10 /* Note, this example requires that you also import into the Mbed
lhiggs 0:03c649c76388 11 compiler the MODDMA project as well as MODSERIAL
lhiggs 0:03c649c76388 12 http://mbed.org/users/AjK/libraries/MODDMA/latest
lhiggs 0:03c649c76388 13 MODDMA.h MUST come before MODSERIAL.h */
lhiggs 0:03c649c76388 14 #include "MODDMA.h" // <--- Declare first
lhiggs 0:03c649c76388 15 #include "MODSERIAL.h" // Flollowed by MODSERIAL
lhiggs 0:03c649c76388 16
lhiggs 0:03c649c76388 17 DigitalOut led1(LED1);
lhiggs 0:03c649c76388 18 DigitalOut led2(LED2);
lhiggs 0:03c649c76388 19 DigitalOut led3(LED3);
lhiggs 0:03c649c76388 20 DigitalOut led4(LED4);
lhiggs 0:03c649c76388 21
lhiggs 0:03c649c76388 22 MODSERIAL pc(USBTX, USBRX);
lhiggs 0:03c649c76388 23
lhiggs 0:03c649c76388 24 /*
lhiggs 0:03c649c76388 25 * As experiement, you can define MODSERIAL as show here and see what
lhiggs 0:03c649c76388 26 * effects it has on the LEDs.
lhiggs 0:03c649c76388 27 *
lhiggs 0:03c649c76388 28 * MODSERIAL uart(TX_PIN, RX_PIN, 512);
lhiggs 0:03c649c76388 29 * With this, the 512 characters sent can straight into the buffer
lhiggs 0:03c649c76388 30 * vary quickly. This means LED1 is only on briefly as the TX buffer
lhiggs 0:03c649c76388 31 * fills.
lhiggs 0:03c649c76388 32 *
lhiggs 0:03c649c76388 33 * MODSERIAL uart(TX_PIN, RX_PIN, 32);
lhiggs 0:03c649c76388 34 * With this, the buffer is smaller than the default 256 bytes and
lhiggs 0:03c649c76388 35 * therefore LED1 stays on much longer while the system waits for
lhiggs 0:03c649c76388 36 * room in the TX buffer.
lhiggs 0:03c649c76388 37 */
lhiggs 0:03c649c76388 38 MODSERIAL uart(TX_PIN, RX_PIN);
lhiggs 0:03c649c76388 39
lhiggs 0:03c649c76388 40 MODDMA dma;
lhiggs 0:03c649c76388 41
lhiggs 0:03c649c76388 42 // This function is called when a character goes from the TX buffer
lhiggs 0:03c649c76388 43 // to the Uart THR FIFO register.
lhiggs 0:03c649c76388 44 void txCallback(void) {
lhiggs 0:03c649c76388 45 led2 = !led2;
lhiggs 0:03c649c76388 46 }
lhiggs 0:03c649c76388 47
lhiggs 0:03c649c76388 48 // This function is called when TX buffer goes empty
lhiggs 0:03c649c76388 49 void txEmpty(void) {
lhiggs 0:03c649c76388 50 led2 = 0;
lhiggs 0:03c649c76388 51 pc.puts(" Done. ");
lhiggs 0:03c649c76388 52 }
lhiggs 0:03c649c76388 53
lhiggs 0:03c649c76388 54 void dmaComplete(void) {
lhiggs 0:03c649c76388 55 led1 = 1;
lhiggs 0:03c649c76388 56 }
lhiggs 0:03c649c76388 57
lhiggs 0:03c649c76388 58 // This function is called when a character goes into the RX buffer.
lhiggs 0:03c649c76388 59 void rxCallback(void) {
lhiggs 0:03c649c76388 60 led3 = !led3;
lhiggs 0:03c649c76388 61 pc.putc(uart.getc());
lhiggs 0:03c649c76388 62 }
lhiggs 0:03c649c76388 63
lhiggs 0:03c649c76388 64 int main() {
lhiggs 0:03c649c76388 65 char s1[] = " *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* ";
lhiggs 0:03c649c76388 66 int c = 'A';
lhiggs 0:03c649c76388 67
lhiggs 0:03c649c76388 68 // Tell MODSERIAL where the MODDMA controller is.
lhiggs 0:03c649c76388 69 pc.MODDMA( &dma );
lhiggs 0:03c649c76388 70
lhiggs 0:03c649c76388 71 // Ensure the baud rate for the PC "USB" serial is much
lhiggs 0:03c649c76388 72 // higher than "uart" baud rate below.
lhiggs 0:03c649c76388 73 pc.baud( PC_BAUD );
lhiggs 0:03c649c76388 74
lhiggs 0:03c649c76388 75 // Use a deliberatly slow baud to fill up the TX buffer
lhiggs 0:03c649c76388 76 uart.baud(1200);
lhiggs 0:03c649c76388 77
lhiggs 0:03c649c76388 78 uart.attach( &txCallback, MODSERIAL::TxIrq );
lhiggs 0:03c649c76388 79 uart.attach( &rxCallback, MODSERIAL::RxIrq );
lhiggs 0:03c649c76388 80 uart.attach( &txEmpty, MODSERIAL::TxEmpty );
lhiggs 0:03c649c76388 81
lhiggs 0:03c649c76388 82 // Loop sending characters. We send 512
lhiggs 0:03c649c76388 83 // which is twice the default TX/RX buffer size.
lhiggs 0:03c649c76388 84
lhiggs 0:03c649c76388 85 led1 = 0;
lhiggs 0:03c649c76388 86
lhiggs 0:03c649c76388 87 // Send the buffer s using DMA channel 7
lhiggs 0:03c649c76388 88 pc.attach_dmaSendComplete( &dmaComplete );
lhiggs 0:03c649c76388 89 pc.dmaSend( s1, sizeof(s1), MODDMA::Channel_7 );
lhiggs 0:03c649c76388 90
lhiggs 0:03c649c76388 91 for (int loop = 0; loop < 512; loop++) {
lhiggs 0:03c649c76388 92 uart.printf("%c", c);
lhiggs 0:03c649c76388 93 c++;
lhiggs 0:03c649c76388 94 if (c > 'Z') c = 'A';
lhiggs 0:03c649c76388 95 }
lhiggs 0:03c649c76388 96
lhiggs 0:03c649c76388 97 led1 = 0; // Show the end of sending by switching off LED1.
lhiggs 0:03c649c76388 98
lhiggs 0:03c649c76388 99 // End program. Flash LED4. Notice how LED 2 and 3 continue
lhiggs 0:03c649c76388 100 // to flash for a short period while the interrupt system
lhiggs 0:03c649c76388 101 // continues to send the characters left in the TX buffer.
lhiggs 0:03c649c76388 102
lhiggs 0:03c649c76388 103 while(1) {
lhiggs 0:03c649c76388 104 led4 = !led4;
lhiggs 0:03c649c76388 105 wait(0.25);
lhiggs 0:03c649c76388 106 }
lhiggs 0:03c649c76388 107 }
lhiggs 0:03c649c76388 108
lhiggs 0:03c649c76388 109 /*
lhiggs 0:03c649c76388 110 * Notes. Here is the sort of output you can expect on your PC/Mac/Linux host
lhiggs 0:03c649c76388 111 * machine that is connected to the "pc" USB serial port.
lhiggs 0:03c649c76388 112 *
lhiggs 0:03c649c76388 113 * *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* *DMA* ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE
lhiggs 0:03c649c76388 114 * FGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
lhiggs 0:03c649c76388 115 * BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
lhiggs 0:03c649c76388 116 * XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRS
lhiggs 0:03c649c76388 117 * TUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNO
lhiggs 0:03c649c76388 118 * PQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJK
lhiggs 0:03c649c76388 119 * LMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFG
lhiggs 0:03c649c76388 120 * HIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQ Done. R
lhiggs 0:03c649c76388 121 *
lhiggs 0:03c649c76388 122 * Note how the DMA blocks the TX buffer sending under standard interrupt control.
lhiggs 0:03c649c76388 123 * Not until the DMA transfer is complete will "normal" buffered TX sending resume.
lhiggs 0:03c649c76388 124 *
lhiggs 0:03c649c76388 125 * Of interest is that last "R" character after the system has said "Done."
lhiggs 0:03c649c76388 126 * This comes from the fact that the TxEmpty callback is made when the TX buffer
lhiggs 0:03c649c76388 127 * becomes empty. MODSERIAL makes use of the fact that the Uarts built into the
lhiggs 0:03c649c76388 128 * LPC17xx device use a 16 byte FIFO on both RX and TX channels. This means that
lhiggs 0:03c649c76388 129 * when the TxEmpty callback is made, the TX buffer is empty, but that just means
lhiggs 0:03c649c76388 130 * the "last few characters" were written to the TX FIFO. So although the TX
lhiggs 0:03c649c76388 131 * buffer has gone empty, the Uart's transmit system is still sending any remaining
lhiggs 0:03c649c76388 132 * characters from it's TX FIFO. If you want to be truely sure all the characters
lhiggs 0:03c649c76388 133 * you have sent have left the Mbed then call txIsBusy(); This function will
lhiggs 0:03c649c76388 134 * return true if characters are still being sent. If it returns false after
lhiggs 0:03c649c76388 135 * the Tx buffer is empty then all your characters have been sent.
lhiggs 0:03c649c76388 136 *
lhiggs 0:03c649c76388 137 * In a similar way, when characters are received into the RX FIFO, the entire
lhiggs 0:03c649c76388 138 * FIFO contents is moved to the RX buffer, assuming there is room left in the
lhiggs 0:03c649c76388 139 * RX buffer. If there is not, any remaining characters are left in the RX FIFO
lhiggs 0:03c649c76388 140 * and will be moved to the RX buffer on the next interrupt or when the running
lhiggs 0:03c649c76388 141 * program removes a character(s) from the RX buffer with the getc() method.
lhiggs 0:03c649c76388 142 */
lhiggs 0:03c649c76388 143
lhiggs 0:03c649c76388 144 #endif