hello, there my application is like that...
(1) calculate size of receive buffer. than read that size of data. again new data comes, then again calculate that size of receive buffer and read that size of data. for that i have to clear buffer after reading data.
can anyone tell me how to do it??
i have tried this way. but its not working for me. i am using nordic sdk 12. i am using uart peripheral code.
from receiver data is coming in different packets at 1s interval. sometimes size is 8 byte or 1D byte. i have to calculate length.
can you tell me how to do it??
void uart_init()
{
uint32_t err_code;
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_Baud9600
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
}
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);
}
if (p_event->evt_type == APP_UART_DATA_READY)
{
count1 = count1+1;
count = count1;
}
}
int uart_return()
{
return count;
}
int main()
{
uart_init();
while(1)
{
while(uart_return() > _len)
{
_len = uart_return();
SEGGER_RTT_printf(0, "task_length:%x\r\n",_len);
nrf_delay_us(_t35);
}
if(_len == 0) return;
uint8_t i;
_frame = (uint8_t*) malloc(_len);
for (i=0 ; i < _len ; i++)
{
app_uart_get(&_frame[i]);
}
}
}