uart, interrupt, rx buffer

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Mar 26, 2015.

  1. bug13

    Thread Starter Well-Known Member

    Feb 13, 2012
    1,208
    38
    Hi guys

    I want to do something like these:

    Code (Text):
    1. typedef struct {
    2.   uint8_t data[UART_BUFFER_SIZE];
    3.   uint16_t num_bytes;
    4.   bool data_is_ready;
    5. }rx_buffer_typedef;
    6.  
    7. //declare rx buffer
    8. rx_buffer_typedef rx_buffer = { {0}, 0 , 0};
    9.  
    10. void interrupt uart_rx (void)
    11. {
    12.    //to-do: check uart_rx flag
    13.    rx_buffer.data[rx_buffer.num_bytes] = uart_read_byte();
    14.    rx_buffer.num_bytes++;
    15.    //how do I know the block of data I want to receive is finished sending
    16.    //and set my data_is_ready = 1;
    17.    //at the same time, let the sender know I can't receive more data
    18.    //until my data is being handled in the main loop?
    19. }
    main loop:

    Code (Text):
    1.  
    2. if (rx_buffer.data_is_ready == 1)
    3. {
    4.     //do something
    5.     //discard uart buffer data when done
    6.     rx_buffer.data_is_ready = 0;
    7. }
    8.  
    So how do I know the block of data I want to receive is finished sending. And at the same time, let the sender know I can't receive more data until my data is being handled in the main loop?

    Is this the right approach for what I want to do? Or is there a better way? Thanks guys!!
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,142
    1,790
    Last edited: Mar 26, 2015
    bug13 likes this.
Loading...