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

How to transmit ten numbers using UART? Suggest me with code.

I am using nRF52832 pca10040 developement board. As I am begineer I dont know much about coding. I am using Eclipse IDE for developement. I want to transmit 1-10 numbers using UART communication. When data sent equal to data received then blink LED if not LED must be off.

I still working on it. Please suggest me complete code with supporting files to run code.

Thank you in advance.

  • This is my code, Please do look and suggest me why it is not working. Tomorrow is the deadline to submit this project. Please rectify code and resend me. Take out your valuable time for me.

    #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 just want to send 0-9 numbers and receive them successfully using UART communication.

  • Hi Kiran,

    Please use the examples, test them out and see how they work. Use them as reference for you application. 

    If something is not working you can debug your application.

    There are several threads about similar projects on Devzone so please utilize the resources. 

     

    Good luck with your project.

Related