diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-10-04 20:10:39 -0400 |
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-10-04 20:10:39 -0400 |
| commit | 16cc3ea9f9f2b7775e2b1681cce525acbf117e79 (patch) | |
| tree | 4ba4b95bf5d2d41463458acbb448b8280e79bd4e /project | |
| parent | 80c01675b3aa51d774eba7db61c6addea9d02f9a (diff) | |
| download | 340-repo-Sowgro-16cc3ea9f9f2b7775e2b1681cce525acbf117e79.tar.gz 340-repo-Sowgro-16cc3ea9f9f2b7775e2b1681cce525acbf117e79.tar.bz2 340-repo-Sowgro-16cc3ea9f9f2b7775e2b1681cce525acbf117e79.zip | |
complete homework 4
Diffstat (limited to '')
| -rw-r--r-- | project/Core/Inc/Devices/UART.h | 3 | ||||
| -rw-r--r-- | project/Core/Inc/Homework/hw4.h | 13 | ||||
| -rw-r--r-- | project/Core/Src/Devices/UART.c | 7 | ||||
| -rw-r--r-- | project/Core/Src/Homework/hw4.c | 29 | ||||
| -rw-r--r-- | project/Core/Src/main.c | 5 |
5 files changed, 55 insertions, 2 deletions
diff --git a/project/Core/Inc/Devices/UART.h b/project/Core/Inc/Devices/UART.h index e9c0f33..03476f6 100644 --- a/project/Core/Inc/Devices/UART.h +++ b/project/Core/Inc/Devices/UART.h @@ -11,7 +11,8 @@ void USART1_IRQHandler(void); void USART2_IRQHandler(void); void USART_Init(USART_TypeDef * USARTx); void USART_Write(USART_TypeDef * USARTx, uint8_t *buffer, uint32_t nBytes); -uint8_t USART_Read(USART_TypeDef * USARTx); +uint8_t USART_Read(USART_TypeDef * USARTx); +uint8_t USART_Read_Nonblocking (USART_TypeDef * USARTx); void USART_Delay(uint32_t us); void USART_IRQHandler(USART_TypeDef * USARTx, uint8_t *buffer, uint32_t * pRx_counter); diff --git a/project/Core/Inc/Homework/hw4.h b/project/Core/Inc/Homework/hw4.h new file mode 100644 index 0000000..2aa852e --- /dev/null +++ b/project/Core/Inc/Homework/hw4.h @@ -0,0 +1,13 @@ +/* + * hw4.h + * + * Created on: Oct 4, 2025 + * Author: sowgro + */ + +#ifndef INC_HOMEWORK_HW4_H_ +#define INC_HOMEWORK_HW4_H_ + +void hw4_run(); + +#endif /* INC_HOMEWORK_HW4_H_ */ diff --git a/project/Core/Src/Devices/UART.c b/project/Core/Src/Devices/UART.c index b1eb30c..7c11e30 100644 --- a/project/Core/Src/Devices/UART.c +++ b/project/Core/Src/Devices/UART.c @@ -108,6 +108,13 @@ uint8_t USART_Read (USART_TypeDef * USARTx) { // Reading USART_DR automatically clears the RXNE flag } +uint8_t USART_Read_Nonblocking (USART_TypeDef * USARTx) { + if (!(USARTx->ISR & USART_ISR_RXNE)) + return 0; + + return ((uint8_t)(USARTx->RDR & 0xFF)); +} + void USART_Write(USART_TypeDef * USARTx, uint8_t *buffer, uint32_t nBytes) { int i; // TXE is cleared by a write to the USART_DR register. diff --git a/project/Core/Src/Homework/hw4.c b/project/Core/Src/Homework/hw4.c new file mode 100644 index 0000000..2154cd4 --- /dev/null +++ b/project/Core/Src/Homework/hw4.c @@ -0,0 +1,29 @@ +/* + * hw4.c + * + * Created on: Oct 4, 2025 + * Author: sowgro + */ + +#include "UART.h" +#include "systick.h" +#include "LED.h" +#include <stdio.h> + + +void read_and_print_char_nonblocking() { + uint8_t ch = USART_Read_Nonblocking(USART2); + printf("%c", ch); + if (ch == '\r') { + printf("\n"); + } +} + +void hw4_run() { + init_systick(); + for (;;) { + delay_systick(); + LED_Toggle(); + read_and_print_char_nonblocking(); + } +} diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index 4063064..b95d7e3 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -8,7 +8,9 @@ #include "LED.h" #include "UART.h" #include "demo.h" +#include "activity7.h" #include <stdio.h> +#include "hw4.h" int main(void){ @@ -17,8 +19,9 @@ int main(void){ LED_Init(); UART2_Init(); + hw4_run(); // application run function // run_demo(); - activity7_run(); +// activity7_run(); } |
