SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By Unomano
#94544
tz wrote:You have to preset the baud rate manually or using something else (only tested at 57600 or faster). It enables agps at the end after uploading.
Get time out at last block:

BINSIZE = 114638 Checksum = 89 Checksumb = 177 :.4f.4b.0OK
114638 left:.4f.4b.0OK
106446 left:.4f.4b.0OK
98254 left:.4f.4b.0OK
90062 left:.4f.4b.0OK
81870 left:.4f.4b.0OK
73678 left:.4f.4b.0OK
65486 left:.4f.4b.0OK
57294 left:.4f.4b.0OK
49102 left:.4f.4b.0OK
40910 left:.4f.4b.0OK
32718 left:.4f.4b.0OK
24526 left:.4f.4b.0OK
16334 left:.4f.4b.0OK
8142 left:.d.a.24.53.6b.79.54.72.61.71.2c.56.65.6e.75.73.36.
By tz
#94569
My current version may have some tweaks. Remember to use a current Eph.dat file (it may be that the one from the server has a problem - also insure you ftp in binary mode)
Code: Select all
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>

static char string[64];
static void readtonull(int fd)
{
    int l;
    char *b = string;
    for (;;) {
        l = read(fd, b, 1);
        if (l <= 0)
            continue;
        if (!*b++)
            break;
    }
    printf("%s\n", string);
}

static unsigned char ephbuf[256 * 1024];
static const unsigned char setagps[8] = { 0xa0, 0xa1, 0x00, 0x01, 0x35, 0x35, 0x0d, 0x0a };
static const unsigned char agpsresp[9] = { 0xa0, 0xa1, 0x00, 0x02, 0x83, 0x35, 0xb6, 0x0d, 0x0a };
static const unsigned char agpsena[9] = { 0xa0, 0xa1, 0x00, 0x02, 0x33, 0x01, 0x32, 0x0d, 0x0a };

int main(int argc, char *argv[])
{
    int fd;
    //    char gpsdev[64] = "/dev/rfcomm0";
    char gpsdev[64] = "/dev/ttyUSB0";
    unsigned i;

    if( argc > 1 )
        strcpy( gpsdev, argv[1] );

    fd = open(gpsdev, O_RDWR);
    if (fd < 0)
        return -10;

    struct termios tio;
    if ((tcgetattr(fd, &tio)) == -1)
        return -1;
    cfmakeraw(&tio);
    if ((tcsetattr(fd, TCSAFLUSH, &tio)) == -1)
        return -1;
    // add: find baud rate

    unsigned char *ephdata;
    long ephbytes;

    ephdata = ephbuf;
    int ofd = open("Eph.dat", O_RDONLY);
    if (ofd < 0)
        return -2;
    ephbytes = read(ofd, ephbuf, 256 * 1024);
    if (ephbytes < 65536)
        return -3;

    // checksum
    unsigned char csuma, csumb = 0;
    for (i = 0; i < 0x10000; i++)
        csumb += ephdata[i];
    csuma = csumb;
    for (; i < ephbytes; i++)
        csuma += ephdata[i];

    // AGPS download startup: send command, get ack - maybe put in loop?
    printf( "Startup\n" );
    do {
        do { // flush input buffer
            i = read(fd, string, 64);
        } while( i == 64 );
        write(fd, setagps, 8);
        i = 0;
        while ( i < 0 || string[0] != '\xa0')
            i = read(fd, string, 1);
        while (i < 64) {
            i += read(fd, &string[i], 64 - i);
            if (i > 0 && string[i-1] == 0x0a)
                break;
        }
    } while( memcmp(&string[i - 9], agpsresp, 9) );
    printf( "Venus Ready\n" );
    
    /* start the transmission */
    sprintf(string, "BINSIZE = %ld Checksum = %d Checksumb = %d ", ephbytes, csuma, csumb);
    printf("%s:", string);
    write(fd, string, strlen(string) + 1);
    readtonull(fd);

#define BLKSIZ 8192
    while (ephbytes > 0) {
        printf("%ld left:", ephbytes);
        write(fd, ephdata, ephbytes > BLKSIZ ? BLKSIZ : ephbytes);
        readtonull(fd);        // OK
        ephbytes -= BLKSIZ;
        ephdata += BLKSIZ;
    }
    // Status "END" or "Error2"
    readtonull(fd);            // END

    sleep(1);
    write(fd, agpsena, 9);
    // maybe get ack?
    sleep(1);
    close(fd);
    return 0;
}
By Unomano
#94589
Added sleep(1) before file transmission:
Code: Select all
printf( "Venus Ready\n" );
    
+ sleep(1)

/* start the transmission */
sprintf(string, "BINSIZE = %ld Checksum = %d Checksumb = %d ", ephbytes, csuma, csumb);
Now it works:
Code: Select all
# agps
Startup
Venus Ready
BINSIZE = 114638 Checksum = 89 Checksumb = 177 :OK
114638 left:OK
106446 left:OK
98254 left:OK
90062 left:OK
81870 left:OK
73678 left:OK
65486 left:OK
57294 left:OK
49102 left:OK
40910 left:OK
32718 left:OK
24526 left:OK
16334 left:OK
8142 left:OK
END
By hps5
#95591
I have following problem:

I set the update rate to 5Hz (SRAM + Flash -> bad idea) and now I am not able to send any commands (beside hot and warm start)
Baudrate is at 38400, receiving data (as before) over FTDI Basic. Error message: Timeout: GPS device no response.
Using SkyTraq 0.4.453

Any suggestion how to set the update rate back or to be able again to communicate with the gps?

thanks in advance!
By tz
#95605
One of the solder shorted jumpers selects flash v.s rom bootup. Check the datasheet and schematics.
By hps5
#95702
thank you, reboot did work (1Hz update rate).
note to myself: read the manual before asking stupid questions :D
By tz
#95708
[quote="hps5"]thank you, reboot did work (1Hz update rate).
note to myself: read the manual before asking stupid questions :D[/quote]

This is unfortunately one of those things that isn't obvious, so the question wasn't stupid. The jumper pads aren't labeled as to function, and you have to read just the right place in the datasheet to know it can even do this.