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

app_uart_init() function error:

Hello,

I wanted to add uart in ble_custom_template project. I have added UART and FIFO Libraries in User include Libraries. Also i set the bits for uart in sdk_config.h. Still I get following error.

Linking xyz.elf
Output/Release/Obj/smart_cap_v1/modbus_handle.o: in function `uart_init':
undefined reference to `app_uart_init'
Build failed

I read other Q and A also as lot of people have this error. But didnt get promisable answer. Please guide me for the same.

Thank you in advance.

Regards.

Parents
  • Hi,

    What toolchain are you using? Have you remembered to add the path of the source files to the project? 

    regards

    Jared 

  • Hello,

    I solved the problem by adding some macro definations from uart example to my project which are not in my project. It solved my error. But right now, I have a problem with app_uart_get function though I can see the data on RX pin. Also it seems NRF_DRV_UART_EVT_RX_DONE is generated. 

    void data_send_uart(uint8_t slaveaddress,uint8_t fn_code,uint16_t start_address,uint16_t number_of_pts)
    {
      char crc_data[2]={0};
      uint8_t data_write[8];
      uint8_t len,Index=0;
      unsigned char CRCLo = 0xff;
      unsigned char CRCHi = 0xff;
      unsigned char *puchMsg;
      uint16_t crc;
    
      data_write[0]=slaveaddress;
      data_write[1]=fn_code;
      data_write[2]=start_address/256;
      data_write[3]=start_address%256;
      data_write[4]=number_of_pts/256;
      data_write[5]=number_of_pts%256;
    
      
    
      len=sizeof(data_write)-2;
      puchMsg= data_write;
      while(len--)
      {
        Index = CRCLo ^ *puchMsg;
        puchMsg++;
        CRCLo = CRCHi ^ auchCRCHi[Index];
        CRCHi = auchCRCLo[Index];
      }
    
      data_write[6]=CRCLo;
      data_write[7]=CRCHi;
    
      printf("CRC Low Byte : %x\n",data_write[6]);
      printf("CRC High Byte : %x\n",data_write[7]);
    
      printf("data sent :\n");
      for(int i=0;i<sizeof(data_write);i++)
      {
        printf("%x\n",data_write[i]);
      }
    
        uint8_t i;
        for(i = 0; i < sizeof(data_write); i++)
        {
            while (app_uart_put(data_write[i]) != NRF_SUCCESS);
        }
    }
    

    static void on_read(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
    {
        uint32_t time = 0;
        ret_code_t err_code;
        char rx_data[8];
        ble_gatts_evt_rw_authorize_request_t  req = p_ble_evt->evt.gatts_evt.params.authorize_request;
    
        data_send_uart(21,4,0,1);
        nrf_delay_ms(500);
        
        //while(uart_received_flag==0);
        uart_received_flag=0;
        //err_code=app_uart_get(rx_data[0]);
        
        for(int i=0;i<8;i++)
        {
            err_code=app_uart_get(&rx_data[i]);
            printf("error code %d",err_code);
            APP_ERROR_CHECK(err_code);
        }
        
        
    
        printf("Rx data :%s",rx_data);
        
        
    
    
    
        if(req.type == BLE_GATTS_AUTHORIZE_TYPE_READ){
            ble_gatts_rw_authorize_reply_params_t response;
            response.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
            response.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
            response.params.read.update = 1;
            response.params.read.offset = 0;
            response.params.read.len =strlen(data);
            response.params.read.p_data = (uint8_t *)data;
    
            err_code=sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle, &response);
            APP_ERROR_CHECK(err_code);
            //NRF_LOG_INFO("Reply function responded with: %d", err_code);
        }
    }


    This is my OnRead Function when there is a read Command and on which we respond to that command
    sd_ble_gatts_rw_authorize_reply function. In this function I am sending some MODBUS Data to my 
    controller (right now i am just shorting TX and RX for testing) and trying to get the data which
    will be present in RX_FIFO and for that, i am using app_uart_get. But everytime I get ERROR CODE 5
    which is NRF_ERROR_NOT_FOUND. Please guide me.
    Thank you so much.

    Regards.
  • Hi,

    Good that you solved the problem.

    NRF_ERROR_NOT_FOUND is returned if If no byte is available in the RX buffer of the app_uart module.

    regards

    Jared 

  • Hello,

    Can you tell me how to receive the data ?

    Can you provide me the snippet?

    Thanks.

Reply Children
Related