Hi there,
I'm using nrf52840 DK and Custom board, SDK 17.0.2, Segger Embedded Studio(SES v5.20
my problem was the code running fine but after a while it will go to the app_error_weak.c file and stop to NRF_BREAKPOINT_COND; line.
i don't understand what is going on please help me out for this.
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "nrf_libuarte_async.h"
#include "nrf_drv_clock.h"
#include <bsp.h>
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_queue.h"
#define pin_rx0 26//NRF_GPIO_PIN_MAP(0, 26)
#define pin_tx0 27//NRF_GPIO_PIN_MAP(0, 27)
#define pin_rx1 NRF_GPIO_PIN_MAP(1, 13)
#define pin_tx1 NRF_GPIO_PIN_MAP(1, 14)
NRF_LIBUARTE_ASYNC_DEFINE(uarte0, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 512, 3);
NRF_LIBUARTE_ASYNC_DEFINE(uarte1, 1, 2, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 512, 3);
static uint8_t text[] = "UART example started.\r\n Loopback:\r\n";
static uint8_t text_size = sizeof(text);
static uint8_t text1[] = "UART111111 example started.\r\n";
static uint8_t text_size1 = sizeof(text1);
static volatile bool m_loopback_phase;
//////////////////////////////////////////
uint8_t send_meter(uint8_t * , uint8_t , int );
float ConvertData(uint8_t*);
uint8_t check_meter_data(void);
char mtr_data_set1[8] = { 0x02, 0x03, 0x00, 0x63, 0x00, 0x5a, 0x35, 0xdc };//02 03 00 63 00 5a 35 dc
char mtr_data_set2[8] = { 0x02, 0x03, 0x00, 0xdf, 0x00, 0x08, 0x75, 0xc5 };//four pararmeter//02 03 00 DF 00 08 75 C5
char mtr_data_set3[8] = { 0x02, 0x03, 0x01, 0x3F, 0x00, 0x04, 0x75, 0xca };//last two parametr//02 03 01 3F 00 04 75 CA
////////////////////////////////
uint16_t index1 = 0;
bool mtr_data_check = false;
#define RS485_RE 15
#define RS485_DE 16
uint8_t check_read = 0;
float v1, v2;
float data_buffer[45];
float level1 = 0;
///////////////////////////////////////////////////////////////////////////
uint8_t read_vitals[8] = { 0x02, 0x03, 0x00, 0x63, 0x00, 0x5a, 0x35, 0xdc };//02 03 00 63 00 5a 35 dc
////////////////////////////////////////////////////////////////////////////
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);
uint8_t uart0_array[256] = {0};
uint8_t uart1_array[512] = {0};
void uart0_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:
//bsp_board_led_invert(0);
break;
case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
//memset(uart0_array,0,sizeof(uart0_array));
//memcpy(uart0_array,p_evt->data.rxtx.p_data,p_evt->data.rxtx.length);
strcat(uart0_array, p_evt->data.rxtx.p_data);
break;
case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
break;
default:
break;
}
}
uint8_t errorr = 0;
void uart1_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;
char bb;
switch (p_evt->type)
{
case NRF_LIBUARTE_ASYNC_EVT_ERROR:
errorr++;
break;
case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
//memset(uart1_array,0,sizeof(uart1_array));
//memcpy(uart1_array,p_evt->data.rxtx.p_data,p_evt->data.rxtx.length);
uart1_array[index1++] = *(p_evt->data.rxtx.p_data);
// strcat(uart1_array,p_evt->data.rxtx.p_data);
if (index1 > 500)
{
index1 = 0;
}
mtr_data_check = true;
break;
case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
break;
default:
break;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void sendSerial(char *sdata, uint8_t len)
{
for (int i = 0; i < len; i++)
{
ret_code_t ret;
/* ret = nrf_serial_write(&uarte1, &sdata[i],
sizeof(sdata[i]),
NULL,
NRF_SERIAL_MAX_TIMEOUT);*/
ret = nrf_libuarte_async_tx(&uarte1, &sdata[i], 1);
APP_ERROR_CHECK(ret);
nrf_delay_ms(2);
}
}
uint8_t readSens(uint8_t list) // to read all the vital parameters from birdmeditech
{
//FE 03 00 00 00 02 D0 04
//char read_vitals[8] = { 0x02, 0x03, 0x00, 0x63, 0x00, 0x0A, 0x35, 0xD3 };//01 03 00 63 00 0A 35 D3
char read_vitals[8] = {0x02, 0x03, 0x00, 0x63, 0x00, 0x5a, 0x35, 0xdc };//01 03 00 63 00 5A 35 EF
char read_vitals1[8] = { 0x02, 0x03, 0x00, 0xdf, 0x00, 0x08, 0x75, 0xc5 };//four pararmeter//02 03 00 DF 00 08 75 C5
char read_vitals2[8] = { 0x02, 0x03, 0x01, 0x3F, 0x00, 0x04, 0x75, 0xca };//last two parametr//02 03 01 3F 00 04 75 CA
nrf_gpio_pin_write(RS485_RE, 0);
nrf_gpio_pin_write(RS485_DE, 1); //for sending (1/0-HIGH/LOW)
nrf_delay_ms(10);
//nrf_libuarte_async_tx(&uarte1, read_vitals, 8);
if (list == 1)
{
sendSerial(read_vitals, 8);// nrf_libuarte_async_tx(&uarte1, read_vitals, 8);//sendSerial(read_vitals, 8);
return 1;
}
else if (list == 2)
{
sendSerial(read_vitals1, 8);//nrf_libuarte_async_tx(&uarte1, read_vitals1, 8);//sendSerial(read_vitals1, 8);
return 2;
}
else if (list == 3)
{
sendSerial(read_vitals2, 8);//nrf_libuarte_async_tx(&uarte1, read_vitals2, 8);//sendSeiial(read_vitals2, 8);
return 3;
}
/* switch (list)
?{
case 1:
sendSerial(read_vitals, 8);
break;
case 2:
sendSerial(read_vitals1, 8);
break;
case 3:
sendSeiial(read_vitals2, 8);
}
*/
//nrf_delay_ms(5);
//nrf_gpio_pin_write(RS485_DE, 0); //for receiving
//nrf_gpio_pin_write(RS485_RE, 0); //for receiving
nrf_delay_ms(10);
}
uint8_t raj_test = 1;
uint8_t check_meter_data(void)
{
if(index1>11)
{
for (uint8_t pos = 0; pos < 512; pos++)
{
if (uart1_array[pos] == 0x02 && uart1_array[pos + 1] == 0x03 && uart1_array[pos + 2] == 0xb4 && (index1>((pos+2+2)+0xb4))) //FC_READ = 0x03
{
data_buffer[0] = ConvertData(&uart1_array[pos + 3]); //V1
data_buffer[1] = ConvertData(&uart1_array[pos + 7]); //V2
data_buffer[2] = ConvertData(&uart1_array[pos + 11]); //V3
v1 = ConvertData(&uart1_array[pos + 15]);
data_buffer[3] = ConvertData(&uart1_array[pos + 19]); //V12
data_buffer[4] = ConvertData(&uart1_array[pos + 23]); //V23
data_buffer[5] = ConvertData(&uart1_array[pos + 27]); //V31
data_buffer[6] = ConvertData(&uart1_array[pos + 31]); //L1
data_buffer[7] = ConvertData(&uart1_array[pos + 35]); //L2
data_buffer[8] = ConvertData(&uart1_array[pos + 39]); //L3
data_buffer[9] = ConvertData(&uart1_array[pos + 71]); //Q1
data_buffer[10] = ConvertData(&uart1_array[pos + 75]); //Q2
data_buffer[11] = ConvertData(&uart1_array[pos + 79]); //Q3
data_buffer[12] = ConvertData(&uart1_array[pos + 83]); //QA
data_buffer[13] = ConvertData(&uart1_array[pos + 87]); //KT1
data_buffer[14] = ConvertData(&uart1_array[pos + 91]); //KT2
data_buffer[15] = ConvertData(&uart1_array[pos + 95]); //KT3
data_buffer[16] = ConvertData(&uart1_array[pos + 99]); //KT
data_buffer[17] = ConvertData(&uart1_array[pos + 103]); //KV1
data_buffer[18] = ConvertData(&uart1_array[pos + 107]); //KV2
data_buffer[19] = ConvertData(&uart1_array[pos + 111]); //KV3
data_buffer[20] = ConvertData(&uart1_array[pos + 115]); //KV
data_buffer[21] = ConvertData(&uart1_array[pos + 119]); //KA1
data_buffer[22] = ConvertData(&uart1_array[pos + 123]); //KA2
data_buffer[23] = ConvertData(&uart1_array[pos + 127]); //KA3
data_buffer[24] = ConvertData(&uart1_array[pos + 131]); //KA
data_buffer[25] = ConvertData(&uart1_array[pos + 147]); //FQ
/*Meter time not taking right now*/
data_buffer[26] = ConvertData(&uart1_array[pos + 155]); //Meter Temp
data_buffer[27] = ConvertData(&uart1_array[pos + 159]); //THDV1
data_buffer[28] = ConvertData(&uart1_array[pos + 163]); //THDV2
data_buffer[29] = ConvertData(&uart1_array[pos + 167]); //THDV3
data_buffer[30] = ConvertData(&uart1_array[pos + 171]); //THDC1
data_buffer[31] = ConvertData(&uart1_array[pos + 175]); //THDC2
data_buffer[32] = ConvertData(&uart1_array[pos + 179]); //THDC3
data_buffer[33] = ConvertData(&uart1_array[pos + 183]); //THDP1
data_buffer[34] = ConvertData(&uart1_array[pos + 187]); //THDP2
data_buffer[35] = ConvertData(&uart1_array[pos + 191]); //THDP3
memset(uart1_array, 0, sizeof(uart1_array));
index1 = 0;
return 1;
}//if
if (uart1_array[pos] == 0x02 && uart1_array[pos + 1] == 0x03 && uart1_array[pos + 2] == 0x10 && (index1>((pos+2+2)+0x10))) //FC_READ = 0x03
{
data_buffer[36] = ConvertData(&uart1_array[pos + 3]);
data_buffer[37] = ConvertData(&uart1_array[pos + 7]);
data_buffer[38] = ConvertData(&uart1_array[pos + 11]);
data_buffer[39] = ConvertData(&uart1_array[pos + 15]);
memset(uart1_array, 0, sizeof(uart1_array));
index1 = 0;
return 1;
}
if (uart1_array[pos] == 0x02 && uart1_array[pos + 1] == 0x03 && uart1_array[pos + 2] == 0x08 && (index1>((pos+2+2)+0x08))) //FC_READ = 0x03
{
data_buffer[40] = ConvertData(&uart1_array[pos + 3]);
data_buffer[41] = ConvertData(&uart1_array[pos + 7]);
memset(uart1_array, 0, sizeof(uart1_array));
index1 = 0;
return 1;
}
}//for
}//if
return 0;
raj_test = 0;
}//check_meter_data
///////////////////////////////////ConvertData//////////////////////////////////////
//float MTR_Data[50];
float ConvertData(uint8_t * data_ptr)
{
union {
char c[4];
float f;
} u;
u.c[3] = *(data_ptr + 2);
u.c[2] = *(data_ptr + 3);
u.c[1] = *data_ptr;
u.c[0] = *(data_ptr + 1);
return u.f;
}
////////////////////////////////////////////////////////////////////////////////////
uint8_t test_fn(void)
{
return 0;
}
/**
@brief Function for main application entry.
*/
int main(void)
{
ret_code_t err_code = NRF_LOG_INIT(app_timer_cnt_get);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("PROGRAM STARTED");
int32_t reset_reason = NRF_POWER->RESETREAS;
NRF_LOG_INFO("Reset reason = 0x%08x.\n", reset_reason);
NRF_POWER->RESETREAS = NRF_POWER->RESETREAS;
bsp_board_init(BSP_INIT_LEDS);
ret_code_t ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
nrf_libuarte_async_config_t nrf_libuarte0_async_config = {
.tx_pin = pin_tx0,//TX_PIN_NUMBER,
.rx_pin = pin_rx0,//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_LOW
};
nrf_libuarte_async_config_t nrf_libuarte1_async_config = {
.tx_pin = pin_tx1,//TX_PIN_NUMBER,
.rx_pin = pin_rx1,//RX_PIN_NUMBER,
.baudrate = NRF_UARTE_BAUDRATE_9600,
.parity = NRF_UARTE_PARITY_EXCLUDED,
.hwfc = NRF_UARTE_HWFC_DISABLED,
.timeout_us = 100,
.int_prio = APP_IRQ_PRIORITY_LOW
};
err_code = nrf_libuarte_async_init(&uarte0, &nrf_libuarte0_async_config, uart0_event_handler, (void *)&uarte0);
NRF_LOG_INFO("err_code: %u", err_code);
APP_ERROR_CHECK(err_code);
err_code = nrf_libuarte_async_init(&uarte1, &nrf_libuarte1_async_config, uart1_event_handler, (void *)&uarte1);
APP_ERROR_CHECK(err_code);
nrf_libuarte_async_enable(&uarte0);
nrf_libuarte_async_enable(&uarte1);
//err_code = nrf_libuarte_async_tx(&uarte0, text, text_size);
//APP_ERROR_CHECK(err_code);
// nrf_delay_ms(5000);
nrf_gpio_cfg_output(RS485_DE);
nrf_gpio_cfg_output(RS485_RE);
nrf_gpio_pin_write(RS485_RE, 0);
nrf_gpio_pin_write(RS485_DE, 1); //for sending (1/0-HIGH/LOW)
nrf_delay_ms(1);
// err_code = nrf_libuarte_async_tx(&uarte1, text1,text_size1);
//APP_ERROR_CHECK(err_code);
while (true)
{
uint8_t cnt = 0;
SET1:
if (!send_meter(mtr_data_set1, 8, 5000))
{
if(cnt<3)
goto SET1;
cnt++;
}
cnt = 0;
SET2:
if (!send_meter(mtr_data_set2, 8, 5000))
{
if(cnt<3)
goto SET2;
cnt++;
}
cnt = 0;
SET3:
if (!send_meter(mtr_data_set3, 8, 5000))
{
if(cnt<3)
goto SET3;
cnt++;
}
}//while
}//main
/** @} */
uint8_t send_meter(uint8_t * ip_array, uint8_t len, int timeout)
{
memset(uart1_array, 0, sizeof(uart1_array));
index1 = 0;
nrf_gpio_pin_write(RS485_RE, 0);
nrf_gpio_pin_write(RS485_DE, 1); //for sending (1/0-HIGH/LOW)
nrf_delay_ms(1);
for (uint8_t i = 0; i < len; i++)
NRF_LOG_INFO("%X", ip_array[i]);
sendSerial(ip_array, len);
// nrf_delay_ms(1000);
nrf_gpio_pin_write(RS485_RE, 0);
nrf_gpio_pin_write(RS485_DE, 0); //for sending (1/0-HIGH/LOW)
nrf_delay_ms(1);
while (timeout--)
{
if (check_meter_data())
{
nrf_delay_ms(1);
return 1;
}
nrf_delay_ms(1);
}//while
nrf_delay_ms(1);
int k = 0;
return 0;
}//send_meter

thank you for advance.