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

UART project building without softdvice

Hello, i am a beginner, i have a doubt that my UART project is building without the softdevice being flashed and the output is not seen on the pins. I wanted to configure some pins as output and assigned them VDD. I used SDK12.2.0. In what cases is Softdevice required to be flashed?

I used nrf51422.

Parents
  • If you want to use Eclipse GCC, this blog may be a bit easier to get started. There are simple UART examples with and without BLE.

    This example code bellow is all you need to write as code in order send and receive UART <-> BLE with a custom service. This code works seamlessly with all nRF5x series. It uses SDK12 for nRF51 series and SDK13 for nRF52 series.

    #include "app_util_platform.h"
    #include "app_scheduler.h"
    
    #include "istddef.h"
    #include "ble_app.h"
    #include "ble_service.h"
    #include "blueio_board.h"
    #include "uart.h"
    #include "custom_board.h"
    #include "iopincfg.h"
    
    #define DEVICE_NAME                     "UARTDemo"                            /**< Name of device. Will be included in the advertising data. */
    
    #define MANUFACTURER_NAME               "I-SYST inc."                       /**< Manufacturer. Will be passed to Device Information Service. */
    #define MODEL_NAME                      "IMM-NRF51x"                            /**< Model number. Will be passed to Device Information Service. */
    #define MANUFACTURER_ID                 ISYST_BLUETOOTH_ID                               /**< Manufacturer ID, part of System ID. Will be passed to Device Information Service. */
    #define ORG_UNIQUE_ID                   ISYST_BLUETOOTH_ID                               /**< Organizational Unique ID, part of System ID. Will be passed to Device Information Service. */
    
    #define APP_ADV_INTERVAL                MSEC_TO_UNITS(64, UNIT_0_625_MS)             /**< The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */
    #define APP_ADV_TIMEOUT_IN_SECONDS      180                                         /**< The advertising timeout (in units of seconds). */
    
    #define MIN_CONN_INTERVAL               MSEC_TO_UNITS(10, UNIT_1_25_MS)             /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
    #define MAX_CONN_INTERVAL               MSEC_TO_UNITS(40, UNIT_1_25_MS)             /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */
    
    void UartTxSrvcCallback(BLESRVC *pBlueIOSvc, uint8_t *pData, int Offset, int Len);
    
    static const ble_uuid_t  s_AdvUuids[] = {
    	{BLUEIO_UUID_UART_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}
    };
    
    static const char s_RxCharDescString[] = {
    		"UART Rx characteristic",
    };
    
    static const char s_TxCharDescString[] = {
    		"UART Tx characteristic",
    };
    
    uint8_t g_ManData[8];
    
    BLESRVC_CHAR g_UartChars[] = {
    	{
    		// Read characteristic
    		BLUEIO_UUID_UART_RX_CHAR,
    		20,
    		BLESVC_CHAR_PROP_READ | BLESVC_CHAR_PROP_NOTIFY,
    		s_RxCharDescString,         // char UTF-8 description string
    		NULL,                       // Callback for write char, set to NULL for read char
    		true,                       // Notify flag for read characteristic
    		NULL,						// Callback on set notification
    		NULL,						// pointer to char default values
    		0,							// Default value length in bytes
    	},
    	{
    		// Write characteristic
    		BLUEIO_UUID_UART_TX_CHAR,	// char UUID
    		20,                         // char max data length
    		BLESVC_CHAR_PROP_WRITEWORESP,	// char properties define by BLUEIOSVC_CHAR_PROP_...
    		s_TxCharDescString,			// char UTF-8 description string
    		UartTxSrvcCallback,         // Callback for write char, set to NULL for read char
    		false,                      // Notify flag for read characteristic
    		NULL,						// Callback on set notification
    		NULL,						// pointer to char default values
    		0							// Default value length in bytes
    	},
    };
    
    uint8_t g_LWrBuffer[512];
    
    const BLESRVC_CFG s_UartSrvcCfg = {
    	BLESRVC_SECTYPE_NONE,	// Secure or Open service/char
    	BLUEIO_UUID_BASE,           // Base UUID
    	BLUEIO_UUID_UART_SERVICE,   // Service UUID
    	2,                          // Total number of characteristics for the service
    	g_UartChars,                // Pointer a an array of characteristic
    	g_LWrBuffer,                // pointer to user long write buffer
    	sizeof(g_LWrBuffer)         // long write buffer size
    };
    
    BLESRVC g_UartBleSrvc;
    
    const BLEAPP_DEVDESC s_UartBleDevDesc {
    	MODEL_NAME,           // Model name
    	MANUFACTURER_NAME,          // Manufacturer name
    	"",                     // Serial number string
    	"0.0",                  // Firmware version string
    	"0.0",                  // Hardware version string
    };
    
    const BLEAPP_CFG s_BleAppCfg = {
    	{ // Clock config nrf_clock_lf_cfg_t
    #ifdef IMM_NRF51822
    		NRF_CLOCK_LF_SRC_RC,	// Source RC
    		1, 1, 0
    #else
    		NRF_CLOCK_LF_SRC_XTAL,	// Source 32KHz XTAL
    		0, 0, NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM
    #endif
    
    	},
    	0, 						// Number of central link
    	1, 						// Number of peripheral link
    	BLEAPP_MODE_APPSCHED,   // Use scheduler
    	DEVICE_NAME,                 // Device name
    	ISYST_BLUETOOTH_ID,     // PnP Bluetooth/USB vendor id
    	1,                      // PnP Product ID
    	0,						// Pnp prod version
    	true,					// Enable device information service (DIS)
    	&s_UartBleDevDesc,
    	g_ManData,              // Manufacture specific data to advertise
    	sizeof(g_ManData),      // Length of manufacture specific data
    	BLEAPP_SECTYPE_NONE,    // Secure connection type
    	BLEAPP_SECEXCHG_NONE,   // Security key exchange
    	NULL,      				// Service uuids to advertise
    	0, 						// Total number of uuids
    	APP_ADV_INTERVAL,       // Advertising interval in msec
    	APP_ADV_TIMEOUT_IN_SECONDS,	// Advertising timeout in sec
    	0,                          // Slow advertising interval, if > 0, fallback to
    								// slow interval on adv timeout and advertise until connected
    	MIN_CONN_INTERVAL,
    	MAX_CONN_INTERVAL,
    	BLUEIO_CONNECT_LED_PORT,    // Led port nuber
    	BLUEIO_CONNECT_LED_PIN,     // Led pin number
    	NULL						// RTOS Softdevice handler
    };
    
    int nRFUartEvthandler(UARTDEV *pDev, UART_EVT EvtId, uint8_t *pBuffer, int BufferLen);
    
    // UART configuration data
    
    static IOPINCFG s_UartPins[] = {
    	{BLUEIO_UART_RX_PORT, BLUEIO_UART_RX_PIN, BLUEIO_UART_RX_PINOP, IOPINDIR_INPUT, IOPINRES_NONE, IOPINTYPE_NORMAL},	// RX
    	{BLUEIO_UART_TX_PORT, BLUEIO_UART_TX_PIN, BLUEIO_UART_TX_PINOP, IOPINDIR_OUTPUT, IOPINRES_NONE, IOPINTYPE_NORMAL},	// TX
    	{BLUEIO_UART_CTS_PORT, BLUEIO_UART_CTS_PIN, BLUEIO_UART_CTS_PINOP, IOPINDIR_INPUT, IOPINRES_NONE, IOPINTYPE_NORMAL},	// CTS
    	{BLUEIO_UART_RTS_PORT, BLUEIO_UART_RTS_PIN, BLUEIO_UART_RTS_PINOP, IOPINDIR_OUTPUT, IOPINRES_NONE, IOPINTYPE_NORMAL},// RTS
    };
    
    const UARTCFG g_UartCfg = {
    	0,
    	s_UartPins,
    	sizeof(s_UartPins) / sizeof(IOPINCFG),
    	1000000,
    	8,
    	UART_PARITY_NONE,
    	1,	// Stop bit
    	UART_FLWCTRL_NONE,
    	true,
    	APP_IRQ_PRIORITY_LOW,
    	nRFUartEvthandler,
    	false,
    };
    
    // UART object instance
    UART g_Uart;
    
    int g_DelayCnt = 0;
    
    void UartTxSrvcCallback(BLESRVC *pBlueIOSvc, uint8_t *pData, int Offset, int Len)
    {
    	g_Uart.Tx(pData, Len);
    }
    
    void BlePeriphEvtUserHandler(ble_evt_t * p_ble_evt)
    {
        BleSrvcEvtHandler(&g_UartBleSrvc, p_ble_evt);
    }
    
    void BleAppInitUserServices()
    {
        uint32_t       err_code;
    
        err_code = BleSrvcInit(&g_UartBleSrvc, &s_UartSrvcCfg);
        APP_ERROR_CHECK(err_code);
    }
    
    void HardwareInit()
    {
    	g_Uart.Init(g_UartCfg);
    }
    
    void BleAppInitUserData()
    {
    
    }
    
    void UartRxChedHandler(void * p_event_data, uint16_t event_size)
    {
    	uint8_t buff[128];
    
    	int l = g_Uart.Rx(buff, 128);
    	if (l > 0)
    	{
    		BleSrvcCharNotify(&g_UartBleSrvc, 0, buff, l);
    	}
    }
    
    int nRFUartEvthandler(UARTDEV *pDev, UART_EVT EvtId, uint8_t *pBuffer, int BufferLen)
    {
    	int cnt = 0;
    	uint8_t buff[20];
    
    	switch (EvtId)
    	{
    		case UART_EVT_RXTIMEOUT:
    		case UART_EVT_RXDATA:
    			app_sched_event_put(NULL, 0, UartRxChedHandler);
    			break;
    		case UART_EVT_TXREADY:
    			break;
    		case UART_EVT_LINESTATE:
    			break;
    	}
    
    	return cnt;
    }
    
    
    int main()
    {
        HardwareInit();
    
        BleAppInit((const BLEAPP_CFG *)&s_BleAppCfg, true);
    
        BleAppRun();
    
    	return 0;
    }
    
  • @yash selecting right answer and closing the question helps others!

Reply Children
No Data
Related