Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

STEVAL-STMDLTE (BG96) MODEM LTE with NRF52840 using libuarte

We are trying to integrate the STEVAL_MODEM_BG96 chip into the NRF52840 for rapid prototyping. Trying to interface nrf52840 with the STEVAL-

STMODLTE chip via UART. Connecting the RX, TX and gnd and seeing the "AT" command after the UART initializes, the modem does not respond. The

question is, did I miss something in the soft ? or do you have any idea please help me, i am stuck. I'm sure I'm missing something simpler, we tried the

same way using MCU (nrf52) with FDTI serial port and it worked fine. Could you help me please? Thanks in advance.

Pins using for UARTE0 : NRF_GPIO_PIN_MAP(1,2), //TX_PIN_NUMBER, NRF_GPIO_PIN_MAP(1,3), //RX_PIN_NUMBER,

by information the chip uses a level shifter to convert the 1.8v to 3.3v, so I am connected in 3.3v between the nRF52 and the modem

Please can you help me ! ,
I'm really stuck .

Best Regards,

Lora


Sniffer using FTDI

and sometimes the software crashes here NRF_BREAKPOINT_COND 


STEVAL-STMODLTE circuit schematic

/**
 * Copyright (c) 2018 - 2021, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/** @file
 * @defgroup libuarte_example_main main.c
 * @{
 * @ingroup libuarte_example
 * @brief Libuarte Example Application main file.
 *
 * This file contains the source code for a sample application using libuarte.
 *
 */

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "nrf_libuarte_async.h"
#include "nrf_drv_clock.h"
#include <bsp.h>
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_queue.h"
#include "nrf_delay.h"


#define MODEM_PWR_EN_GPIO_PORT                                      (NRF_GPIO_PIN_MAP(1,4)) 
#define GPIO_PIN_RESET                                              (0)
#define GPIO_PIN_SET                                                (1)       
#define SIZE_BUFFER_RX                                              (50)
#define BG96_BOOT_TIME                                              (5500U)  


uint8_t CMD_ATI[] = "ATI\n";
uint16_t size_cmd = sizeof(CMD_ATI);


unsigned char buffer_rx[SIZE_BUFFER_RX];
uint32_t numbre_data_received = 0;


NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

static volatile bool m_resp_bg96_ok = false;
bool m_loopback_phase = false;

typedef struct {
    uint8_t * p_data;
    uint32_t length;
} buffer_t;

NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);

static uint8_t command[]="123456789012345123456534623465351235412344123412341234";


/**
 * @brief Function used to wakeup the MODEM 
 */
void sys_ctrl_bg96_power_on(void)
{

  /* Reference: Quectel BG96 Hardware Design V1.4
  *  PWRKEY   connected to MODEM_PWR_EN (inverse pulse)
  *  RESET_N  connected to MODEM_RST    (inverse)
  *
  * Turn ON module sequence
  *
  *                PWRKEY  PWR_EN  modem_state
  * init             0       1      OFF
  * T=0 ms           1       0      OFF
  * T1=30 ms         0       1      BOOTING
  * T2=T1+500 ms     1       0      BOOTING
  * T3=T1+4800 ms    1       0      RUNNING
  */

  /* First, turn OFF module in case it was not switched off correctly (can occur after
   *  a manual reset).
   * Set PWR_EN to 0 at least 650ms
   */
  
  nrf_gpio_cfg_output(MODEM_PWR_EN_GPIO_PORT);
  
  nrf_gpio_pin_write(MODEM_PWR_EN_GPIO_PORT, GPIO_PIN_SET);
  nrf_delay_ms(700U);
  nrf_gpio_pin_write(MODEM_PWR_EN_GPIO_PORT, GPIO_PIN_RESET);
  nrf_delay_ms(1000U);

  /* Power ON sequence */
  /* Set PWR_EN to 1 (initial state) */
  nrf_gpio_pin_write(MODEM_PWR_EN_GPIO_PORT, GPIO_PIN_SET);
  nrf_delay_ms(50U);

  /* Set PWR_EN to 0 during at least 30ms as defined by Quectel */
  nrf_gpio_pin_write(MODEM_PWR_EN_GPIO_PORT, GPIO_PIN_RESET);
  nrf_delay_ms(30U);

  /* Set PWR_EN to 1 during at least 500ms */
  nrf_gpio_pin_write(MODEM_PWR_EN_GPIO_PORT, GPIO_PIN_SET);
  nrf_delay_ms(510U);

  /* Set PWR_EN to 0 */
  nrf_gpio_pin_write(MODEM_PWR_EN_GPIO_PORT, GPIO_PIN_RESET);

  /* wait for Modem to complete its booting procedure */
  /*"Waiting %d millisec for modem running...", BG96_BOOT_TIME)*/
  nrf_delay_ms(BG96_BOOT_TIME);
  /* ... done */
}


void send_command(uint8_t cmd[], uint16_t size)
{
    ret_code_t err_code;

    memset(command, 0, sizeof(command));

    for (int i=0; i<size; i++)
    {
        command[i] = cmd[i];   
    }

    do {
        err_code = nrf_libuarte_async_tx(&libuarte, command, sizeof(command));
        }
    while (err_code == NRF_ERROR_BUSY);

    APP_ERROR_CHECK(err_code);

    nrf_delay_ms(300);
}


void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    ret_code_t ret;

    switch (p_evt->type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            break;
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            
            if((unsigned char)*(p_evt->data.rxtx.p_data) !=0 )
            {
                buffer_rx[numbre_data_received]=(unsigned char)*(p_evt->data.rxtx.p_data);
                numbre_data_received = numbre_data_received + 1;
            }

            if((buffer_rx[numbre_data_received - 1] == '\r') || 
                (buffer_rx[numbre_data_received - 1 ] == '\n'))
            {
                char * find_BG96 = strstr((const char *)buffer_rx, (const char *)"BG96");

                if( find_BG96 == NULL)
                {
                    send_command("ATI\n", sizeof("ATI\n"));
                    send_command("AT\n",sizeof("AT\n"));
                    send_command("AT+GSN\n",sizeof("AT+GSN\n"));
                    send_command("AT+CSQ\n",sizeof("AT+CSQ\n"));
                    send_command("AT+CMGF=1\n",sizeof("AT+CMGF=1\n"));
                }
                else
                {
                    for (int i = 0; i < LEDS_NUMBER; i++)
                    {
                    bsp_board_led_invert(i);
                    nrf_delay_ms(500);
                    }
                }

                if( numbre_data_received >= SIZE_BUFFER_RX )
                {
                    memset(buffer_rx, 0, numbre_data_received);
                    numbre_data_received = 0;
                }
             }

              m_loopback_phase = true;
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            if (m_loopback_phase)
            {
                nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
            }
            break;
        default:
            break;
    }
}



/**
 * @brief Function for main application entry.
 */
int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);

    //sys_ctrl_bg96_power_on();
    
    ret_code_t ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
  
    nrf_drv_clock_lfclk_request(NULL);

    ret_code_t err_code = NRF_LOG_INIT(app_timer_cnt_get);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    nrf_libuarte_async_config_t nrf_libuarte_async_config = {
            .tx_pin     = NRF_GPIO_PIN_MAP(1,2), //TX_PIN_NUMBER,
            .rx_pin     = NRF_GPIO_PIN_MAP(1,3), //RX_PIN_NUMBER,
            .baudrate   = NRF_UARTE_BAUDRATE_115200,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 100,
            .int_prio   = APP_IRQ_PRIORITY_HIGH,
            .pullup_rx = NRF_GPIO_PIN_PULLUP
    };

    err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);

    APP_ERROR_CHECK(err_code);

    nrf_libuarte_async_enable(&libuarte);

    send_command("ATI\n", sizeof("ATI\n"));
    send_command("AT\n",sizeof("AT\n"));
    send_command("AT+GSN\n",sizeof("AT+GSN\n"));
    send_command("AT+CSQ\n",sizeof("AT+CSQ\n"));
    send_command("AT+CMGF=1\n",sizeof("AT+CMGF=1\n"));

    while(true)
    {
        NRF_LOG_FLUSH();
    }
}

Parents
  • Hi,

    and sometimes the software crashes here NRF_BREAKPOINT_CON

    This is from the error handler, and if you test with a debug build you can check the file name, line number and error code. That should give you a lot to go on (see An introduction to error handling in nRF5 projects).

    Sniffer using FTDI

    It is not easy to say much without knowing more, but it looks like there could be a baud rate issue. Is the baud rate configuration the same on both ends? And do both sides use an accurate clock source? As you are already using the clock driver that could be accomplished on the nRF side by calling nrf_drv_clock_hfclk_request().

  • Hi Einar,

    Thank you for your feedback .
    I work on a project, the objective is to communicate nRF52840 with (  STEVAL-STMODLTE puce with modem BG96  steval-stmodlte ) .
    I use an example libuarte in SDK nRF52840, the problem is that I don't receive the correct data from the modem .
    I attached a screenshot of the data received . and yesterday i did a test, i communicated with a direct FTDI cable on the tx, rx, gnd of the modem and PC using a tool to send AT command and i received the same incorrect data .
    By info on the chip STEVAL-STMODLTE there is a usb port to send AT commands and it works well when you connect to the micro usb port, and also at the output of the chip i measure 3,3v and at the output of the modem BG96 i measure 1,8v because there is a shifter level in schematics  Link ( 8 . Schematic diagrams).
    Concerning the baudrate, when I connect in usb micro, I send the command AT : AT+IPR? it responds well 115200  and in MCU nRF52 i config the baudrate as 115200 .
    Thank you for your help .
    Best regards,
Reply
  • Hi Einar,

    Thank you for your feedback .
    I work on a project, the objective is to communicate nRF52840 with (  STEVAL-STMODLTE puce with modem BG96  steval-stmodlte ) .
    I use an example libuarte in SDK nRF52840, the problem is that I don't receive the correct data from the modem .
    I attached a screenshot of the data received . and yesterday i did a test, i communicated with a direct FTDI cable on the tx, rx, gnd of the modem and PC using a tool to send AT command and i received the same incorrect data .
    By info on the chip STEVAL-STMODLTE there is a usb port to send AT commands and it works well when you connect to the micro usb port, and also at the output of the chip i measure 3,3v and at the output of the modem BG96 i measure 1,8v because there is a shifter level in schematics  Link ( 8 . Schematic diagrams).
    Concerning the baudrate, when I connect in usb micro, I send the command AT : AT+IPR? it responds well 115200  and in MCU nRF52 i config the baudrate as 115200 .
    Thank you for your help .
    Best regards,
Children
Related