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

Can't instantiate uart driver

Hello all,

I try to instantiate an uart driver using NRF_DRV_UART_INSTANCE macro, but I got the following error :

sdk/components/drivers_nrf/uart/nrf_drv_uart.h:97:1: error: invalid conversion from 'void*' to 'NRF_UARTE_Type*' [-fpermissive]
 }
 ^
drivers/uart.hpp:41:27: note: in expansion of macro 'NRF_DRV_UART_INSTANCE'
     nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);
                           ^

bellow is my code :

#include "nrf_drv_uart.h"
#include "app_error.h"
#include "nrf.h"

void uartEventHandler(nrf_drv_uart_evt_type_t *p_event)
{}

void initUART()
{
    nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);
    uint32_t err_code;
    nrf_drv_uart_config_t uart_cfg;

    uart_cfg.pseltxd=RX_PIN_NUMBER;
    uart_cfg.pselrxd=TX_PIN_NUMBER;
    uart_cfg.pselcts=RTS_PIN_NUMBER;
    uart_cfg.pselrts=CTS_PIN_NUMBER;
    uart_cfg.hwfc=UART_CONFIG_HWFC_Disabled;
    uart_cfg.parity=false;
    uart_cfg.baudrate=UART_BAUDRATE_BAUDRATE_Baud115200;
    uart_cfg.use_easy_dma = true;

    err_code = nrf_drv_uart_init(&uart, &uart_cfg, uartEventHandler);
    nrf_drv_uart_rx_enable(&uart_cfg);
}

thank you in advance for help ! there is my sdk config file : sdk_config.h my toolchain : arm-gcc-none-eabi-4.9-2015q3. my main.cpp file : main.cpp

Parents
  • You should do something like this:

    #include "nrf_drv_uart.h"
    
    const nrf_drv_uart_t uart = NRF_DRV_UART_INSTANCE(0);
    
    void uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context)
    {
    }
    
    void initUART()
    {
        uint32_t err_code;
        nrf_drv_uart_config_t uart_cfg;
    
        uart_cfg.pseltxd        = RX_PIN_NUMBER;
        uart_cfg.pselrxd        = TX_PIN_NUMBER;
        uart_cfg.pselcts        = RTS_PIN_NUMBER;
        uart_cfg.pselrts        = CTS_PIN_NUMBER;
        uart_cfg.hwfc           = NRF_UART_HWFC_DISABLED;
        uart_cfg.parity         = NRF_UART_PARITY_EXCLUDED;
        uart_cfg.baudrate       = NRF_UART_BAUDRATE_115200;
        uart_cfg.use_easy_dma   = true;
    
        err_code = nrf_drv_uart_init(&uart, &uart_cfg, uart_event_handler);
        APP_ERROR_CHECK(err_code);
        nrf_drv_uart_rx_enable(&uart);
    }
    
  • hello, that's compile, I also modify this code part :

    typedef struct
    {
        union
        {
    #if (defined(UART_IN_USE) || (UART_ENABLED == 0))
        NRF_UART_Type * p_uart;   ///< Pointer to a structure with UART registers.
    #endif
    #if (defined(UARTE_IN_USE))
        NRF_UARTE_Type * p_uarte; ///< Pointer to a structure with UARTE registers.
    #endif
    
        } reg;
        uint8_t drv_inst_idx;     ///< Driver instance index.
    } nrf_drv_uart_t;
    

    and I suppress the p_uart = in the NRF_DRV_UART_INSTANCE macro. As I said, the program compile, but it didn't work, this is my main function :

    #define BSP_UART_SUPPORT #include "bsp.h" #include "sdk_config.h" #include "nrf_delay.h"

    #include "nrf_drv_uart.h"

    const nrf_drv_uart_t uart_test = NRF_DRV_UART_INSTANCE(0);

    void uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context) { //static uint8_t rec_byte=0; switch(p_event->type) { case NRF_DRV_UART_EVT_RX_DONE:

        break;
    
        case NRF_DRV_UART_EVT_ERROR:
    
        default:
        break;
    }
    

    }

    int main(void) {

    /*Parameters for uart driver*/
    uint32_t err_code;
    nrf_drv_uart_config_t uart_cfg;
    
    uart_cfg.pseltxd        = RX_PIN_NUMBER;
    uart_cfg.pselrxd        = TX_PIN_NUMBER;
    uart_cfg.pselcts        = RTS_PIN_NUMBER;
    uart_cfg.pselrts        = CTS_PIN_NUMBER;
    uart_cfg.hwfc           = NRF_UART_HWFC_DISABLED;
    uart_cfg.parity         = NRF_UART_PARITY_EXCLUDED;
    uart_cfg.baudrate       = NRF_UART_BAUDRATE_115200;
    uart_cfg.use_easy_dma   = true;
    
    err_code = nrf_drv_uart_init(&uart_test,&uart_cfg,uart_event_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_uart_rx_enable(&uart_test);
    uint8_t test[4]={0,255,0,255};
    static uint8_t i=0;
    
    while( true )
    {
      while(i<4)
      {
          err_code = nrf_drv_uart_tx(&uart_test, &test[i], 1);
          if(err_code ==NRF_SUCCESS )
          {
          }
          nrf_delay_ms(1000);
          i++;
      }
      i=0;
    };
    return 0;
    

    }

    in the oscilloscope, I don't have any signal in Tx output pin :/

Reply
  • hello, that's compile, I also modify this code part :

    typedef struct
    {
        union
        {
    #if (defined(UART_IN_USE) || (UART_ENABLED == 0))
        NRF_UART_Type * p_uart;   ///< Pointer to a structure with UART registers.
    #endif
    #if (defined(UARTE_IN_USE))
        NRF_UARTE_Type * p_uarte; ///< Pointer to a structure with UARTE registers.
    #endif
    
        } reg;
        uint8_t drv_inst_idx;     ///< Driver instance index.
    } nrf_drv_uart_t;
    

    and I suppress the p_uart = in the NRF_DRV_UART_INSTANCE macro. As I said, the program compile, but it didn't work, this is my main function :

    #define BSP_UART_SUPPORT #include "bsp.h" #include "sdk_config.h" #include "nrf_delay.h"

    #include "nrf_drv_uart.h"

    const nrf_drv_uart_t uart_test = NRF_DRV_UART_INSTANCE(0);

    void uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context) { //static uint8_t rec_byte=0; switch(p_event->type) { case NRF_DRV_UART_EVT_RX_DONE:

        break;
    
        case NRF_DRV_UART_EVT_ERROR:
    
        default:
        break;
    }
    

    }

    int main(void) {

    /*Parameters for uart driver*/
    uint32_t err_code;
    nrf_drv_uart_config_t uart_cfg;
    
    uart_cfg.pseltxd        = RX_PIN_NUMBER;
    uart_cfg.pselrxd        = TX_PIN_NUMBER;
    uart_cfg.pselcts        = RTS_PIN_NUMBER;
    uart_cfg.pselrts        = CTS_PIN_NUMBER;
    uart_cfg.hwfc           = NRF_UART_HWFC_DISABLED;
    uart_cfg.parity         = NRF_UART_PARITY_EXCLUDED;
    uart_cfg.baudrate       = NRF_UART_BAUDRATE_115200;
    uart_cfg.use_easy_dma   = true;
    
    err_code = nrf_drv_uart_init(&uart_test,&uart_cfg,uart_event_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_uart_rx_enable(&uart_test);
    uint8_t test[4]={0,255,0,255};
    static uint8_t i=0;
    
    while( true )
    {
      while(i<4)
      {
          err_code = nrf_drv_uart_tx(&uart_test, &test[i], 1);
          if(err_code ==NRF_SUCCESS )
          {
          }
          nrf_delay_ms(1000);
          i++;
      }
      i=0;
    };
    return 0;
    

    }

    in the oscilloscope, I don't have any signal in Tx output pin :/

Children
No Data
Related