This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problem sending chars

Hi team,

I have to create a program which sends messages from one dongle to another. Now I have ported radio transmit and receive + USB CDC ACM programs for two 52840 dongles. Also each of them can be seen as USB serial devices and can output messages on the terminal. Now, I can transmit only integers... How to transmit chars? When I try to use sprintf function I get hieroglyphs on the terminal. Also I tried to set packet variable with some chars on the tx side and then I got ASCII values in the other side... Thanks for the answers.

Rx dongle main():

ret_code_t ret;
  static const app_usbd_config_t usbd_config = {
      .ev_state_proc = usbd_user_ev_handler
  };

  bsp_board_init(BSP_INIT_LEDS);
  
  nrf_drv_clock_init(); 
  nrf_drv_clock_hfclk_request(NULL); // for HF 32MHz external X-tal
  while(!nrf_drv_clock_hfclk_is_running()) ; // Just waiting
  nrf_drv_clock_lfclk_request(NULL); // for LF 32.768kHz external X-tal
  while(!nrf_drv_clock_lfclk_is_running()) ; 
  /// end clock set

 /// end clock set
  app_usbd_serial_num_generate();
  ret = app_usbd_init(&usbd_config);
  APP_ERROR_CHECK(ret);

  app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
  ret = app_usbd_class_append(class_cdc_acm);
  APP_ERROR_CHECK(ret);

  if (USBD_POWER_DETECTION) {
      ret = app_usbd_power_events_enable();
      APP_ERROR_CHECK(ret);
  }
  else {
      app_usbd_enable();
      app_usbd_start();
  }


 radio_configure();
 NRF_RADIO->PACKETPTR = (uint32_t)&packet;
 
while(true)
  {

uint32_t             received = read_packet();
char result[3]; 

sprintf(result,"%ul",received);

size_t size = sprintf(m_tx_buffer,result, frame_counter);
ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);

if (ret == NRF_SUCCESS)
  {
   ++frame_counter;
  }

  nrf_delay_ms(10);
  }
}

Tx dongle main():

ret_code_t ret;
  static const app_usbd_config_t usbd_config = {
      .ev_state_proc = usbd_user_ev_handler
  };

  bsp_board_init(BSP_INIT_LEDS);

  nrf_drv_clock_init(); 
  nrf_drv_clock_hfclk_request(NULL); // for HF 32MHz external X-tal
  while(!nrf_drv_clock_hfclk_is_running()) ; // Just waiting
  nrf_drv_clock_lfclk_request(NULL); // for LF 32.768kHz external X-tal
  while(!nrf_drv_clock_lfclk_is_running()) ; // Just waiting

  app_usbd_serial_num_generate();
  ret = app_usbd_init(&usbd_config);
  APP_ERROR_CHECK(ret);

  app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
  ret = app_usbd_class_append(class_cdc_acm);
  APP_ERROR_CHECK(ret);

  if (USBD_POWER_DETECTION) {
      ret = app_usbd_power_events_enable();
      APP_ERROR_CHECK(ret);
  }
  else {
      app_usbd_enable();
      app_usbd_start();
  }

  radio_configure();
  NRF_RADIO->PACKETPTR = (uint32_t)&packet;   // Set payload pointer

  while(true)
  {
  app_usbd_event_queue_process();

if (packet != 0) {

  send_packet();
  m_send_flag;
  static int  frame_counter;
  
  nrf_delay_ms(10); 
  
    }
  }
}

Parents Reply Children
Related