Hi,
How can I create a char getchar(void) function that reads a character from a buffer? The following code is how the buffer gets the data.
So the buffer in question is rx_buffer
Edit: inserted code tags like this [code] your code [/code]
How can I create a char getchar(void) function that reads a character from a buffer? The following code is how the buffer gets the data.
Code:
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
uint8_t i;
if (huart->Instance == USART3) //is uart3 active?
{
if (rx_index == 0) //if data is no being received
{
for (i=0;i<30;i++)
{
rx_buffer[I]=0; //clean the buffer
}
}
else if(rx_index<30) //if there is space in the buffer
{
rx_buffer[rx_index++]= rx_data; // store data in the buffer
}
else
{
//ignore data
}
HAL_UART_Receive_IT (&huart3, rx_data, 1); //activate reception
}
}
Edit: inserted code tags like this [code] your code [/code]