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

Transmit and Receive data via UART

I have compiled and debugged the temperature_pca10036 code from nRF5_SDK_v11.0. I have used termite terminal for getting info about transferring of data from nRF52832 board to PC. And i haven't got the output for the code. Is this, the way correct. Please help with simple code for analysing the data transfer in UART.

Parents
  • Thankyou sir for your kind approach. I have made the code correctly as per your guide and its working in good.

  • Hi Sadasivam,

    I am facing same problem. I am using nRF52832 pca10040. IDE using is eclipse.

    I want to transmit 0-9 numbers using UART. The transmitted data equals to received data the LED should blink otherwise it should be off state.

    I am begineer, that is why facing small problem. Please help me with the code.

    Thank you in advance.

    Here is the code that I developed take a look suggest changes.

    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf.h"
    #include "bsp.h"
    
    
    
    #define MAX_TEST_DATA_BYTES     (15U)
    #define UART_TX_BUF_SIZE 256
    #define UART_RX_BUF_SIZE 256
    
    
    
    //  UART error handler function.
    
    
    void uart_error_handle(app_uart_evt_t * p_event)
    {
        if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_communication);
        }
        else if (p_event->evt_type == APP_UART_FIFO_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_code);
        }
    }
    
    
    
    
    // LED glow function: When data Transmitted is equal to data Received then LED glow up else stays off.
    
    
    void led_blink()
    {
    
        bsp_board_leds_init();
    
    
        while (true)
        {
            for (int i = 0; i < 1; i++)
            {
                bsp_board_led_invert(i);
                nrf_delay_ms(500);
            }
        }
    }
    
    //   UART transmit function.
    
    
     #if ((Enable_UART_TxDecimalNumber==1) || (Enable_UART_TxFloatNumber==1))
    
    
    void UART_Tx(uint32_t dec_no, uint8_t nod)
    {
    		uint8_t i=0;
    
    		printf("\nEnter decimal no to transmit:");
    		scanf("\n%d", &dec_no);
    
    		if(dec_no==0)																			//decimal number to transmit
    		{
    			for(i=0; ((i<nod) && (i<max_dttx)); i++)											//number of digits to transmit
    			a[i] = 0x00;																		//maximum number of digits to transmit
    		}
    		else if
    		{
    			for(i=0; i<nod; i++)
    			{
    				if(dec_no!=0)
    				{
    					a[i] = util_GetMod32(dec_no,10);
    					dec_no = dec_no/10;
    				}
    
    
    		else if( (nod == dttx) || (nod > max_dttx))												//total numbers to transmit
    			{
    				break;
    			}
    		else
    			{
    				a[i]=0;
    			}
    		}
    	}
    
    	while(i)
    	{
    		UART_TxChar(util_Dec2Ascii(a[i-1]));													//Convert decimal to ASCII
    		i--;
    	}
    
    	void led_blink();
    }
    
    #endif
    
    
    
    //  main Function.
    
    
    int main(void)
    {
        uint32_t err_code;
    
        bsp_board_leds_init();
    
        const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              APP_UART_FLOW_CONTROL_ENABLED,
              false,
              UART_BAUDRATE_BAUDRATE_Baud19200
          };
    
        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle,
                             APP_IRQ_PRIORITY_LOWEST,
                             err_code);
    
        APP_ERROR_CHECK(err_code);
    
    
        UART_Tx();
    
    
    
    	return 0;
    }
    
    
    
    
    
    
    

  • I see you posted you question in this thread. Please continue discussion in that thread.

Reply Children
No Data
Related