Hi guys
I want to do something like these:
main loop:
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!!
I want to do something like these:
Code:
typedef struct {
uint8_t data[UART_BUFFER_SIZE];
uint16_t num_bytes;
bool data_is_ready;
}rx_buffer_typedef;
//declare rx buffer
rx_buffer_typedef rx_buffer = { {0}, 0 , 0};
void interrupt uart_rx (void)
{
//to-do: check uart_rx flag
rx_buffer.data[rx_buffer.num_bytes] = uart_read_byte();
rx_buffer.num_bytes++;
//how do I know the block of data I want to receive is finished sending
//and set my data_is_ready = 1;
//at the same time, let the sender know I can't receive more data
//until my data is being handled in the main loop?
}
Code:
if (rx_buffer.data_is_ready == 1)
{
//do something
//discard uart buffer data when done
rx_buffer.data_is_ready = 0;
}
Is this the right approach for what I want to do? Or is there a better way? Thanks guys!!