Troubleshooting Initialization Failures in Icarus IoT Dev Board (nRF9160): Error Code -8 During GPS and IoT Module Setup

I'm working on a tracking project using the Icarus IoT Dev Board (nRF9160), which employs both NB-IoT and GPS functionalities. During the project, I encountered an issue where, after successfully initializing either the GPS or the IoT module, attempting to initialize the other module fails. The error message returned is:

`<err> lte_lc: Could not send AT command, error: -8`.

I am using toolchain version 1.5.1.

I am seeking to understand the potential reasons behind this error. Specifically, why might the initialization of one module interfere with the initialization of the other, resulting in the inability to send AT commands? What are the possible underlying causes for this error code, and how can they be resolved to ensure successful initialization of both the GPS and IoT modules on the nRF9160 board?

Parents
  • In this project, we aim to utilize NB-IoT and GPS technologies to develop a system that can accurately determine and communicate its location. The project involves setting up and controlling the GPS module using various AT commands and managing the LTE connection. 

    #### Objective

    To initialize and control the GPS using NB-IoT and ensure seamless LTE connectivity. The system should:

    1. Initialize the modem and configure it for NB-IoT and GPS usage.
    2. Start, stop, and restart the GPS as required.
    3. Ensure LTE connectivity for data transmission.

    #### Code Overview

    1. **AT Commands for System Configuration**:
    ```c
    #define AT_XSYSTEMMODE "AT%XSYSTEMMODE=0,1,1,2"
    #define AT_ACTIVATE_GPS "AT+CFUN=1"

    static const char *const at_commands[] = {
    AT_XSYSTEMMODE,
    AT_ACTIVATE_GPS
    };
    ```

    2. **GPS Control Macros**:
    ```c
    #define GNSS_INIT_AND_START 1
    #define GNSS_STOP 2
    #define GNSS_RESTART 3
    ```

    3. **Setup Modem Function**:
    ```c
    static int setup_modem(void)
    {
    for (int i = 0; i < ARRAY_SIZE(at_commands); i++)
    {
    if (at_cmd_write(at_commands[i], NULL, 0, NULL) != 0)
    {
    return -1;
    }
    }
    return 0;
    }
    ```

    4. **GPS Control Function**:
    ```c
    static int gnss_ctrl(uint32_t ctrl)
    {
    int retval;
    nrf_gnss_delete_mask_t delete_mask = 0;

    if (ctrl == GNSS_INIT_AND_START)
    {
    gnss_fd = nrf_socket(NRF_AF_LOCAL, NRF_SOCK_DGRAM, NRF_PROTO_GNSS);
    if (gnss_fd < 0)
    {
    printk("Could not init socket (err: %d)\n", gnss_fd);
    return -1;
    }
    nrf_gnss_fix_interval_t fix_interval = 1;
    retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_FIX_INTERVAL, &fix_interval, sizeof(fix_interval));
    if (retval != 0)
    {
    printk("Failed to set fix interval value\n");
    return -1;
    }
    }

    if ((ctrl == GNSS_INIT_AND_START) || (ctrl == GNSS_RESTART))
    {
    retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_START, &delete_mask, sizeof(delete_mask));
    if (retval != 0)
    {
    printk("Failed to start GPS\n");
    return -1;
    }
    }

    if (ctrl == GNSS_STOP)
    {
    retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_STOP, &delete_mask, sizeof(delete_mask));
    if (retval != 0)
    {
    printk("Failed to stop GPS\n");
    return -1;
    }
    }
    printk("GNSS control operation successful\n");
    return 0;
    }
    ```

    #### Main Loop Initialization

    In the main loop, the GPS is initialized first:

    ```c
    printk("Starting GPS application\n");

    if (setup_modem() != 0)
    {
    printk("Failed to initialize modem\n");
    return -1;
    }

    if (gnss_ctrl(GNSS_INIT_AND_START) != 0)
    {
    printk("Failed to start GNSS\n");
    return -1;
    }
    ```

    After initializing the GPS, LTE is initialized:

    ```c
    lte_lc_init_and_connect();
    ```

    #### Issue

    The error encountered is: `<err> lte_lc: Could not send AT command, error: -8`.

    #### Expected Outcome

    The project should successfully initialize the modem, control the GPS, and establish an LTE connection without any errors.

Reply
  • In this project, we aim to utilize NB-IoT and GPS technologies to develop a system that can accurately determine and communicate its location. The project involves setting up and controlling the GPS module using various AT commands and managing the LTE connection. 

    #### Objective

    To initialize and control the GPS using NB-IoT and ensure seamless LTE connectivity. The system should:

    1. Initialize the modem and configure it for NB-IoT and GPS usage.
    2. Start, stop, and restart the GPS as required.
    3. Ensure LTE connectivity for data transmission.

    #### Code Overview

    1. **AT Commands for System Configuration**:
    ```c
    #define AT_XSYSTEMMODE "AT%XSYSTEMMODE=0,1,1,2"
    #define AT_ACTIVATE_GPS "AT+CFUN=1"

    static const char *const at_commands[] = {
    AT_XSYSTEMMODE,
    AT_ACTIVATE_GPS
    };
    ```

    2. **GPS Control Macros**:
    ```c
    #define GNSS_INIT_AND_START 1
    #define GNSS_STOP 2
    #define GNSS_RESTART 3
    ```

    3. **Setup Modem Function**:
    ```c
    static int setup_modem(void)
    {
    for (int i = 0; i < ARRAY_SIZE(at_commands); i++)
    {
    if (at_cmd_write(at_commands[i], NULL, 0, NULL) != 0)
    {
    return -1;
    }
    }
    return 0;
    }
    ```

    4. **GPS Control Function**:
    ```c
    static int gnss_ctrl(uint32_t ctrl)
    {
    int retval;
    nrf_gnss_delete_mask_t delete_mask = 0;

    if (ctrl == GNSS_INIT_AND_START)
    {
    gnss_fd = nrf_socket(NRF_AF_LOCAL, NRF_SOCK_DGRAM, NRF_PROTO_GNSS);
    if (gnss_fd < 0)
    {
    printk("Could not init socket (err: %d)\n", gnss_fd);
    return -1;
    }
    nrf_gnss_fix_interval_t fix_interval = 1;
    retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_FIX_INTERVAL, &fix_interval, sizeof(fix_interval));
    if (retval != 0)
    {
    printk("Failed to set fix interval value\n");
    return -1;
    }
    }

    if ((ctrl == GNSS_INIT_AND_START) || (ctrl == GNSS_RESTART))
    {
    retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_START, &delete_mask, sizeof(delete_mask));
    if (retval != 0)
    {
    printk("Failed to start GPS\n");
    return -1;
    }
    }

    if (ctrl == GNSS_STOP)
    {
    retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_STOP, &delete_mask, sizeof(delete_mask));
    if (retval != 0)
    {
    printk("Failed to stop GPS\n");
    return -1;
    }
    }
    printk("GNSS control operation successful\n");
    return 0;
    }
    ```

    #### Main Loop Initialization

    In the main loop, the GPS is initialized first:

    ```c
    printk("Starting GPS application\n");

    if (setup_modem() != 0)
    {
    printk("Failed to initialize modem\n");
    return -1;
    }

    if (gnss_ctrl(GNSS_INIT_AND_START) != 0)
    {
    printk("Failed to start GNSS\n");
    return -1;
    }
    ```

    After initializing the GPS, LTE is initialized:

    ```c
    lte_lc_init_and_connect();
    ```

    #### Issue

    The error encountered is: `<err> lte_lc: Could not send AT command, error: -8`.

    #### Expected Outcome

    The project should successfully initialize the modem, control the GPS, and establish an LTE connection without any errors.

Children
No Data
Related