We are trying to integrate the STEVAL-STMODLTE Link 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 sending the "AT" command after the UART initializes, the modem does not respond.
The question is, am I missing something about the software ? or do you have any idea please to help me, i'm 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.
By Information, I configured the voltage level GPIO at 3.3 v and I can wakeup the modem using PWRKEY Pin
sometimes also the software it crashes on : NRF_BREAKPOINT_COND .
Best regards.
Loura
/**
* 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\r\n";
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);
/**
* @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 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:
//Toggle LED1
bsp_board_led_invert(0);
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)
{
// BG96 not found, Toggle LED2
bsp_board_led_invert(1);
//sys_ctrl_bg96_power_on();
}
else
{
// BG96 found, Toggle LED3
bsp_board_led_invert(2);
m_resp_bg96_ok = true;
}
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:
// Toggle LED4
bsp_board_led_invert(3);
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;
}
}
void send_command(uint8_t cmd[])
{
ret_code_t err_code;
unsigned int cmd_size = strlen(cmd);
do {
err_code = nrf_libuarte_async_tx(&libuarte, cmd, cmd_size);
}
while (err_code == NRF_ERROR_BUSY);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(1000);
}
/**
* @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
};
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);
while( m_resp_bg96_ok == false)
{
send_command(CMD_ATI);
nrf_delay_ms(400);
}
while(true)
{
NRF_LOG_FLUSH();
}
}
/** @} */
Best regards,