• AVR Freaks

Hot!ATtiny202 & ZOE-M8Q GPS (I2C)

Author
Kevil
New Member
  • Total Posts : 28
  • Reward points : 0
  • Joined: 2019/09/09 13:29:33
  • Location: 0
  • Status: offline
2020/02/28 18:53:42 (permalink)
0

ATtiny202 & ZOE-M8Q GPS (I2C)

Any advice how to make the example program work? When I copy the code to main.c, see attachment, it compiles successfully but actually the main program run just atmel_start_init(); function. What I am doing wrong?

I would like to get GPS coordinates (NMEA GNGLL) from ZOE-M8Q GPS (uBlox receiver) but I don't fully understand how to send commands to it and read data by using ATtiny202.

I2C Slave Address 0x42, uBlox Register Address 0xFF within the slave.
I need to send 8 bytes command (B5 62 F0 01 00 00 F1 C3) to uBlox Register Address 0xFF and than wait for data available (52 bytes). The currently available number of bytes in the message stream can be read at addresses 0xFD (MSB) and 0xFE (LSB).

The register at address 0xFF allows the data stream to be read. If there is no data awaiting transmission from the receiver, then this register will deliver the value 0xFF, which cannot be the first byte of a valid message. If message data is ready for transmission, then successive reads of register 0xFF will deliver the waiting message data.

I created program for ATtiny202 with I2C component on start.atmel.com, it automatically generated Source Files/examples/src/i2c_master_example.c, and imported it in MPLAB X IDE.

Any advice how to make the example work? When I copy the i2c_master_example.c to main.c, see picture, it compiles successfully but in the main program only the function atmel_start_init(); is called. What I am doing wrong?

Attached Image(s)

#1

5 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3463
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: ATtiny202 & ZOE-M8Q GPS (I2C) 2020/02/29 02:07:34 (permalink)
    0
    I'd suggest to start by hooking up the M8Q to an Arduino and get one of the many examples running.
    Once this works, you may consider to port this application to the ATtiny202.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    Kevil
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2019/09/09 13:29:33
    • Location: 0
    • Status: offline
    Re: ATtiny202 & ZOE-M8Q GPS (I2C) 2020/02/29 03:29:18 (permalink)
    +1 (1)
    With Arduino Pro Mini ATMega328P 3.3V and SparkFun_Ublox_Arduino_Library.h I can get LAT LON without any problems.

        #include <Wire.h> //Needed for I2C to GPS
         
        #include "SparkFun_Ublox_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Ublox_GPS
        SFE_UBLOX_GPS myGPS;
         
        void setup()
        {
          Serial.begin(115200);
          Serial.println("SparkFun Ublox Example");
         
          Wire.begin();
         
          if (myGPS.begin() == false)
          {
            Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
            while (1);
          }
        }
         
        void loop()
        {
          myGPS.checkUblox(); //See if new data is available. Process bytes as they come in.
         
          long latitude = myGPS.getLatitude();
          double lat = latitude * 1E-7;
          Serial.print(F("Lat: "));
          Serial.print(lat,5);
         
          long longitude = myGPS.getLongitude();
          double lon = longitude * 1E-7;
          Serial.print(F(" Long: "));
          Serial.println(lon, 5);
         
          delay(250);
        }




    #3
    du00000001
    Just Some Member
    • Total Posts : 3463
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: ATtiny202 & ZOE-M8Q GPS (I2C) 2020/03/02 09:25:55 (permalink)
    -1 (1)
    Now compare what you've messed (in main.c) with the .ino:
    • "loop()" somewhat equals "main()".
    • Do you see any function implementations in loop() ?
     
    BTW: what are your C skills? Non-existing ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    Kevil
    New Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2019/09/09 13:29:33
    • Location: 0
    • Status: offline
    Re: ATtiny202 & ZOE-M8Q GPS (I2C) 2020/03/02 09:50:21 (permalink)
    0
    Although I am not expert in C for sure I know what I am doing. The Arduino program above is running well without any problems. In the loop I am calling functions  myGPS.getLatitude() and myGPS.getLongitude() which are part of the #include "SparkFun_Ublox_Arduino_Library.h".

    Finally I was successful to compile ATtiny202 example program in MPLAB X IDE. The problem is that, I don't fully understand how to use I2C commands.

    #include <atmel_start.h>
    #include <i2c_types.h>
    #include <i2c_simple_master.h>
    #include <utils/atomic.h>

    #define slave_adr 0x42
    #define slave_reg_adr 0xff

    uint8_t write_data [8] = {0xB5, 0x62, 0xF0, 0x01, 0x00, 0x00, 0xF1, 0xC3};
    uint8_t read_data[52]; // e.g. $GPGLL,4717.11634,N,00833.91297,E,124923.00,A,A*6E<CR><LF>

    /** For ACK/NAK confirmation from the receiver we just need to read back 10 bytes
     and test the byte at the position 3 i.e. 0x01 ACK or 0x00 NAK see below
    UBX-ACK-ACK [10] = {0xB5, 0x62, 0x05, 0x01, 0x02, 0x00, 0xF0, 0x01, 0xF9, 0x0C};
    UBX-ACK-NAK [10] = {0xB5, 0x62, 0x05, 0x00, 0x02, 0x00, 0xF0, 0x01, 0xF8, 0x07};
     */

    /** Structure passed into read_handler to describe the actions to be performed by the handler */
    typedef struct {
        uint8_t *data;
        uint8_t size;
    } transfer_descriptor_t;

    /** This callback is called when the initial write of the pointer register has finished.
        This callback controls the second phase of the I2C transaction, the read of the
        targeted register after a REPEATED START.
     */
    i2c_operations_t read_handler(void *d) {
        transfer_descriptor_t *desc = (transfer_descriptor_t *) d;
        I2C_0_set_buffer((void *) desc->data, desc->size);
        // Set callback to terminate transfer and send STOP after read is complete
        I2C_0_set_data_complete_callback(i2c_cb_return_stop, NULL);
        return i2c_restart_read; // Send REPEATED START before read
    }

    /** Performs the following transfer sequence:
    1. Send SLA+W, Data1
    2. Send RepeatedStart, SLA+R, Read Data1, Read Data2
    3. Send Stop

    This transfer sequence is typically done to first write to the slave the address in
    the slave to read from, thereafter to read N bytes from this address.
     */
    void do_transfer(uint8_t adr, uint8_t *data, uint8_t size) {
        transfer_descriptor_t d = {data, size};
        while (!I2C_0_open(slave_adr))
            ; // sit here until we get the bus..
        // This callback specifies what to do after the first write operation has completed
        // The parameters to the callback are bundled together in the aggregate data type d.
        I2C_0_set_data_complete_callback((void *) read_handler, &d);
        // If we get an address NACK, then try again by sending SLA+W
        I2C_0_set_address_nack_callback((void *) i2c_cb_restart_write, NULL);
        // Transmit one byte
        I2C_0_set_buffer((void *) &adr, 1);
        // Start a Write operation
        I2C_0_master_operation(false);
        while (I2C_BUSY == I2C_0_close())
            ; // sit here until the entire chained operation has finished
    }

    int main(void) {
        /* Initializes MCU, drivers and middleware */
        atmel_start_init();

        do_transfer(slave_reg_adr, read_data, 52);

         /* Replace with your application code */
        while (1) {
        }
    }


    #5
    du00000001
    Just Some Member
    • Total Posts : 3463
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: ATtiny202 & ZOE-M8Q GPS (I2C) 2020/03/02 11:33:19 (permalink)
    0
    Now that you've removed the function implementations from within main() . . . Smile
     
    The ...set...something...callback() functions serve to dynamically set the address of some callback function.
    I personally never use these - instead overwriting the indirect call of the callback function by a direct call where necessary.
     
    In the files generated (especially in the header files), there should be a bit of information to be found.
    Otherwise: reading the function code usually unveils what/how to use. These drivers are not too difficult...

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5