Hello
I want to make an application based on the multi NUS sample
https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/enter-the-multi-nus-a-simple-wireless-uart-network
https://github.com/NordicMatt/multi-NUS
but I want to send timer state to all peripheral devices every 1500ms. I want start this feature after send "_START_" from computer COM port.
I want also to print on UART received messages from peripheral devices with timer state (timestamp) from the moment they were received.
I have problem. I tried to init timer and read timer satus. I tried to do something simmilar to this sample:
https://github.com/sigurdnev/ncs-playground/blob/master/samples/pulse_detector/src/main.c
this is my code snippet:
#define TIMER_INTERVAL_MS 1500 static const nrfx_timer_t m_timer_count = NRFX_TIMER_INSTANCE(1); static const nrfx_timer_t m_timer_read = NRFX_TIMER_INSTANCE(2); static uint32_t timer_value = 0; void timer_handler_count(nrf_timer_event_t event_type, void * p_context) { uint32_t count = nrfx_timer_capture_get(&m_timer_count, NRF_TIMER_CC_CHANNEL0); if(count > 0) { if( ((count % TIMER_INTERVAL_MS) == 0) ) { timer_value = count; printk("Timerrr valueee: %lu\n", timer_value); timestamp_send(); } } } void timer_handler_read(nrf_timer_event_t event_type, void * p_context) { uint32_t count = nrfx_timer_capture_get(&m_timer_count, NRF_TIMER_CC_CHANNEL0); if(count > 0) { if( ((count % TIMER_INTERVAL_MS) == 0) ) { timer_value = count; printk("Timer value: %lu\n", timer_value); timestamp_send(); } } } static void timer_init(void) { // Configure m_timer_count for counting of low to high events on GPIO nrfx_err_t err; nrfx_timer_config_t timer_cfg = { .mode = NRF_TIMER_MODE_LOW_POWER_COUNTER, .bit_width = NRF_TIMER_BIT_WIDTH_32, .p_context = NULL, }; err = nrfx_timer_init(&m_timer_count, &timer_cfg, timer_handler_count); if (err != NRFX_SUCCESS) { printk("nrfx_timer_init failed with: %d\n", err); } // Configure m_timer_read for reading the counter timer at a given interval COUNT_READ_INTERVAL timer_cfg.mode = NRF_TIMER_MODE_TIMER; err = nrfx_timer_init(&m_timer_read, &timer_cfg, timer_handler_read); if (err != NRFX_SUCCESS) { printk("nrfx_timer_init failed with: %d\n", err); } nrfx_timer_extended_compare(&m_timer_read, NRF_TIMER_CC_CHANNEL0, nrfx_timer_ms_to_ticks(&m_timer_read, TIMER_INTERVAL_MS), NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); IRQ_CONNECT(TIMER1_IRQn, IRQ_PRIO_LOWEST, nrfx_timer_1_irq_handler, NULL, 0); IRQ_CONNECT(TIMER2_IRQn, IRQ_PRIO_LOWEST, nrfx_timer_2_irq_handler, NULL, 0); nrfx_timer_clear(&m_timer_count); nrfx_timer_clear(&m_timer_read); nrfx_timer_enable(&m_timer_count); nrfx_timer_enable(&m_timer_read); }
Referring to the sending part I wrote code, but it is not sending message to peripherals
void timestamp_send() { convert_number_to_text(timer_value, data_to_send, sizeof(data_to_send)); int length = sizeof(data_to_send); char * message = data_to_send; int err = 0; static bool broadcast = false; static int nus_index = 0; const size_t num_nus_conns = bt_conn_ctx_count(&conns_ctx_lib); // ==== SENDING BASED ON BROADCAST IN multi_nus_send() FUNCTION ===== (not working) /* for (size_t i = 0; i < num_nus_conns; i++) { const struct bt_conn_ctx *ctx = bt_conn_ctx_get_by_id(&conns_ctx_lib, i); if (ctx) { struct bt_nus_client *nus_client = ctx->data; if (nus_client != NULL) { err = bt_nus_client_send(nus_client, message, length); if (err) { LOG_WRN("Failed to send --TIMESTAMP-- over BLE connection" "(err %d)", err); }else{ LOG_INF("Sent to server (timestamp) %d: %s", nus_index, message); } bt_conn_ctx_release(&conns_ctx_lib, (void *)ctx->data); err = k_sem_take(&nus_write_sem, NUS_WRITE_TIMEOUT); if (err) { LOG_WRN("NUS send TIMESTAMP timeout"); } } } } */ // Annother attempt (also not working) // /* struct uart_data_t *txx = k_malloc(sizeof(data_to_send)); uint16_t ln = sizeof(data_to_send); for(uint32_t ii=0; ii<ln; ii++) { txx->data[ii] = data_to_send[ii]; } txx->len = ln; multi_nus_send(txx); // */ }
What should I modify to implement starting sending timestamp from timer after send "_START_" from computer COM port (and send "_STOP_" to stop sending timestamp) ?
Can you help me resolve this problem?
Best Regards