diff options
author | xengineering <mail2xengineering@protonmail.com> | 2020-11-01 16:10:30 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2020-11-01 16:28:06 +0100 |
commit | a10ed370febb7168246acebc6cc8492a173170ce (patch) | |
tree | 3df8a08063bc43ebd0011a8f6172eb4949655c6a /usart_irq/main.c | |
parent | 7d0035a6940394c01398a7c2f061093319c328f7 (diff) | |
download | stm32f103c8-examples-a10ed370febb7168246acebc6cc8492a173170ce.tar stm32f103c8-examples-a10ed370febb7168246acebc6cc8492a173170ce.tar.zst stm32f103c8-examples-a10ed370febb7168246acebc6cc8492a173170ce.zip |
Complete Write Functions in USART Lib
Diffstat (limited to 'usart_irq/main.c')
-rw-r--r-- | usart_irq/main.c | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/usart_irq/main.c b/usart_irq/main.c index 8c79471..48ce18b 100644 --- a/usart_irq/main.c +++ b/usart_irq/main.c @@ -11,14 +11,13 @@ #define DELAY 1000000 -#define RX_BUFFER_SIZE 50 -#define TX_BUFFER_SIZE 50 +#define RX_BUFFER_SIZE 1000 +#define TX_BUFFER_SIZE 1000 void clock_init(void); void gpio_init(void); void delay(void); -int _write(int file, char *ptr, int len); USART usart3; @@ -26,20 +25,18 @@ USART usart3; int main(void) { - uint8_t rx_buffer[RX_BUFFER_SIZE]; - uint8_t tx_buffer[TX_BUFFER_SIZE]; - + // setup clock_init(); gpio_init(); + uint8_t rx_buffer[RX_BUFFER_SIZE]; + uint8_t tx_buffer[TX_BUFFER_SIZE]; usart_init(&usart3, rx_buffer, RX_BUFFER_SIZE, tx_buffer, TX_BUFFER_SIZE); - gpio_set(GPIOC, GPIO13); - - char welcome[] = "Hello world!\r"; - usart_write(&usart3, welcome); + // welcome message + usart_writeln(&usart3, "This is a demo of USART via IRQ. Just type something!"); + // return any input uint8_t buff; - while(1){ if (usart_read_bytes(&usart3, &buff, 1)){ usart_write_bytes(&usart3, &buff, 1); @@ -60,6 +57,7 @@ void gpio_init(void) { gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); gpio_clear(GPIOC, GPIO13); + gpio_set(GPIOC, GPIO13); } @@ -69,22 +67,3 @@ void delay(void) __asm__("nop"); } } - - -int _write(int file, char *ptr, int len) -{ - int i; - - if (file == STDOUT_FILENO || file == STDERR_FILENO) { - for (i = 0; i < len; i++) { - if (ptr[i] == '\n') { - uint8_t cr = (uint8_t)'\r'; - usart_write_bytes(&usart3, &cr, 1); - } - usart_write_bytes(&usart3, (uint8_t *)&ptr[i], 1); - } - return i; - } - errno = EIO; - return -1; -} |