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

NRF52 Uart to Ble Bridge

Hi!

I'm trying to transfer data from UART to BLE in NRF52810. NRF52810 connects MSP430 controller via UART, MSP430 sends packet of 16 bytes lenght every 2ms (500 times in a second). UART baud rate is 460800 (NRF is uses 0x075F7000 constant). NRF52810 uses UART with EasyDMA, SDK 16.0 and app_uart_fifo from SDK. I also use hardware flow control for uart - and it works when distance between devices is short (40 cm).

But then the distance between peripheral and cenrtal increase over 5 meters, RTS pin sticks hight level(deactivate) fast enough and stays forever, although receiver FIFO is empty. Only next data transfer makes it low(active). So what is the reason? Maybe it is some performance problem?

Is there any solution?

  • RTS pin sticks hight level(deactivate) fast enough and stays forever, although receiver FIFO is empt

    RTS is hardware controlled and will only assert when the uart(e) hardware fifo has >= 4 bytes in it. In other words: Your observation is not 100% correct.

    Further analysing requires us to be able to look into your source code.

  • void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
    
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = 12,
            .cts_pin_no   = 10, 
            .flow_control = APP_UART_FLOW_CONTROL_ENABLED,
            .use_parity   = false,
            .baud_rate    =  NRF_UART_BAUDRATE_460800
        };
    
        APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_HIGHEST,
                           err_code);
        
        APP_ERROR_CHECK(err_code);
    }

    int main(void)
    {
    
        uart_init();
        // some other init
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        int err_code = app_timer_create(&timer_id, APP_TIMER_MODE_REPEATED , &LedTimerHandler);
        if (err_code){
          //printf("\napp_timer_create ERROR! %d\n\n", err_code);
        }
        err_code = app_timer_start(timer_id, 65,NULL);
        if (err_code){
          //printf("\napp_timer_start ERROR! %d\n\n", err_code);
        }   
    
        uint32_t size=0;
        uint32_t time;
        uint32_t last_send_time;    
        
        last_send_time = GetTickCounter();
        while(1){
            size = fifo_length(&m_rx_fifo);                  
            if (size) {                      
                time = GetTickCounter();
                if(time < last_send_time){
                    time = time + 0x1000000;
                }           
                if(((time - last_send_time) >= (int)((2 * RTC_FREQ_F)/1000)) || (size>=BTH_MAX_PACKET_SIZE))  {    
                    app_fifo_read(&m_rx_fifo, buf, &size);
                    BLE_Send(buf, size);
                    last_send_time = time;        
                }
            }
        }    
    }

    int BLE_Send(unsigned char* Data, unsigned short len){
      
      int err_code;
      int sended = 0;
      unsigned short SendLen;
      unsigned SendRetryCount = 0;
    
      uint32_t time;
      uint32_t last_send_time;
    
      do{
        if (len > BLE_MAX_LEN){
          SendLen = BLE_MAX_LEN;
        }
        else{
          SendLen = len;
        }
        last_send_time = GetTickCounter();
        SendRetryCount = 0;
        DataSended = 0;
        do
        {
          err_code = my_ble_nus_data_send((uint8_t*)&Data[sended], &SendLen, m_conn_handle);
    
    
          time = GetTickCounter();
          if(time < last_send_time){
            time = time + 0x1000000;
          }                                
          
          if ((time - last_send_time) >= (int)((BTH_SEND_TIMEOUT * RTC_FREQ_F)/1000)){
            return sended;
          }
          
        } while ( (err_code == NRF_ERROR_BUSY) | (err_code == NRF_ERROR_RESOURCES) );
    
        len -= SendLen;
        sended += SendLen;
      }while(len);
      
      return sended;
    }

    Sometimes RTS pin goes hi(deactive) and never come back. 

Related