fix(UART FIFO):
Removed Buffer clearing Disabled UART FIFO
This commit is contained in:
parent
e6665c2195
commit
59fa7829da
|
@ -7,10 +7,10 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/uart.h"
|
||||
|
||||
#define UART_ID uart0
|
||||
#define BAUD_RATE 115200 // Baud rate of UART
|
||||
#define UART_BUF_SIZE 64 // Buffer size for UART
|
||||
|
||||
#define UART_TX_PIN 16 // GPIO for UART TX pin
|
||||
#define UART_RX_PIN 17 // GPIO for UART RX pin
|
||||
|
@ -33,15 +33,6 @@ static void uart_transmit(char *uart_input) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear buffer (read until buffer size is UART_BUF_SIZE)
|
||||
* This is to prevent the program from printing out garbage
|
||||
* for the first few characters received or during pseudo button press
|
||||
* @return void
|
||||
*/
|
||||
static void uart_buf_clr() {
|
||||
while (uart_is_readable(UART_ID) && uart_getc(UART_ID) != UART_BUF_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a character through UART0 and prints it out
|
||||
|
@ -60,8 +51,6 @@ static void uart_receive(char *uart_output) {
|
|||
*uart_output = '2'; // If '1' is received, print '2'
|
||||
}
|
||||
|
||||
uart_buf_clr(); // Clear buffer
|
||||
|
||||
printf("%c\n", *uart_output);
|
||||
}
|
||||
}
|
||||
|
@ -76,11 +65,15 @@ static void pin_init() {
|
|||
gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART);
|
||||
gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART);
|
||||
|
||||
// Disable UART FIFO for data to be tx/rx immediately
|
||||
uart_set_fifo_enabled(UART_ID, false);
|
||||
|
||||
// Pseudo button init
|
||||
gpio_set_dir(PSEUDO_BTN, GPIO_IN);
|
||||
|
||||
// Enable pull up resistor
|
||||
gpio_set_pulls(PSEUDO_BTN, true, false);
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
Loading…
Reference in New Issue