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

UART Example, timed messages.

By combining some examples, I'm starting to understand how the UART examples works.

Using Keil 8.0.0, and the PCA10003 Board, I'm trying to send a burst of messages over the ble, to look at throughput and delay.

Ideally, I'd want as much timer precision as possible, but I'm failing to get the timers to work. As I understand the example, it uses the app timer, but does not seem to actually start or trigger any timers.

After failing to have the app timers trigger events, I figured I'd try using the method mentioned here: devzone.nordicsemi.com/.../ (I'm assuming this is referring to the timer_pca10028 example)

However, if I edit the run-time environment to include the required libraries. I get several errors during compilation (that does not occur when I compile the timer_pca10028 example).

So, how would I set up a fairly accurate (preferably 1ms) timer without interfering with the UART handling on a PCA10003 board?

The errors stem from the nrf_drv_timer.c. Despite the runtime environment not complaining about dependencies.

C:\Keil_v5\ARM\PACK\NordicSemiconductor\nRF_Drivers\2.0.0\timer\nrf_drv_timer.c(38): error:  #29: expected an expression
  };
C:\Keil_v5\ARM\PACK\NordicSemiconductor\nRF_Drivers\2.0.0\timer\nrf_drv_timer.c(28): error:  #1514: an empty initializer is invalid for an array with unspecified bound
  static const nrf_drv_timer_config_t m_default_config[] = {
C:\Keil_v5\ARM\PACK\NordicSemiconductor\nRF_Drivers\2.0.0\timer\nrf_drv_timer.c(264): warning:  #177-D: function "nrf_drv_timer_interrupt_handle" was declared but never referenced
  static void nrf_drv_timer_interrupt_handle(NRF_TIMER_Type * p_reg, uint32_t timer_id)
C:\Keil_v5\ARM\PACK\NordicSemiconductor\nRF_Drivers\2.0.0\timer\nrf_drv_timer.c: 1 warning, 4 errors

I've also hooked up a button to a simple message spammer. Using the ble_nus_string_send() to send a message of max length.

static void data_send(void)
{
    uint32_t err_code;
    static uint8_t data[BLE_NUS_MAX_DATA_LEN] = {0};
    uint8_t msgnum=0;    
    while (1)
    {
if (msgnum>100)
    {
    printf("%s","moooo");
    return;
}
    err_code = ble_nus_string_send(&m_nus, data, BLE_NUS_MAX_DATA_LEN);
			
    if (err_code != NRF_SUCCESS &&
        err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
        err_code != NRF_ERROR_INVALID_STATE &&
        err_code != BLE_ERROR_NO_TX_BUFFERS)
    {
        APP_ERROR_CHECK(err_code);
    }

    // If transmission succeeded, increment payload. 
    if (err_code == NRF_SUCCESS)
    {
					msgnum +=1;
        data[0] += 1;
        for (uint8_t i = 0; i < BLE_NUS_MAX_DATA_LEN-1; i++)
        {
            if (data[i] == 0)
                ++data[i+1];
            else 
                break;
        }
    }
    else
    {
					m_is_sending_data=false;
					printf("%d",err_code);
        break;
    }

}

}

However, this results in the button only sending 8 messages, before triggering a BLE_ERROR_INVALID_CONN_HANDLE error. Am I correct in assuming that this is due to a connection event ending?

If so, I'm assuming there is some sort of ble_evt that can be responded to?

Related