Advertisement
edensheiko

stm32

Nov 25th, 2022
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | Software | 0 0
  1. /*
  2.  * RTG.c
  3.  *
  4.  *
  5.  *
  6.  */
  7. #include "../../TESTING/Inc/UART.h"
  8. uint8_t uart5_flag_calback = 0; //Flag when UART completes receiving data from user
  9. uint8_t uart4_flag_calback = 0;
  10. uint8_t uart5_flag_h = 0;
  11.  
  12. void UART_main() {
  13.  
  14.     UART_send(20,(uint8_t*)"some_data",10);
  15.     UART_receive(20,(uint8_t*)"",10);
  16.  
  17.     // 4->2 old
  18.     // 4->5 new 4tx -> 5rx
  19.     // 5->4 new_2 5tx -> 4rx
  20.  
  21. }
  22. //todo: clear buffer
  23. //todo: add it in case of failure
  24. void UART_send(uint8_t data_size,uint8_t *data_sent,uint8_t iteration) {
  25.  
  26.     uint8_t buffer[data_size];
  27.     printf("Start of program:\r\n");
  28.     HAL_UART_Receive_DMA(UART_RECEIVE, buffer, data_size);
  29.     HAL_Delay(100);
  30.     HAL_UART_Transmit(UART_TRANSMIT, data_sent, data_size,
  31.     TIMEOUT_TIME);
  32.     while (--iteration) {
  33.         if (uart5_flag_calback) {
  34.             HAL_UART_Receive_DMA(UART_RECEIVE, buffer, data_size);
  35.             printf("Data_sent: %s\r\n", buffer);
  36.             uart5_flag_calback = 0;
  37.             HAL_UART_Transmit(UART_TRANSMIT, data_sent, data_size,
  38.             TIMEOUT_TIME);
  39.             HAL_Delay(DELAY_TIME);
  40.         }
  41.  
  42.     }
  43. }
  44.  
  45. void UART_receive(uint8_t data_size,uint8_t *data_sent,uint8_t iteration) {
  46.     uint8_t buffer[data_size];
  47.     printf("Start of program:\r\n");
  48.     HAL_UART_Receive_DMA(UART_TRANSMIT, buffer, data_size);
  49.     HAL_Delay(100);
  50.     HAL_UART_Transmit(UART_RECEIVE, data_sent, data_size,
  51.     TIMEOUT_TIME);
  52.     while (--iteration) {
  53.         if (uart5_flag_calback) {
  54.             HAL_UART_Receive_DMA(UART_RECEIVE, buffer, data_size);
  55.             printf("Data_Received: %s\r\n", buffer);
  56.             uart4_flag_calback = 0;
  57.             HAL_UART_Transmit(UART_RECEIVE, data_sent, data_size,
  58.             TIMEOUT_TIME);
  59.             HAL_Delay(DELAY_TIME);
  60.         }
  61.  
  62.     }
  63. }
  64.  
  65. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
  66.     if (huart == UART_RECEIVE)
  67.         uart5_flag_calback = 1;
  68.     if (huart == UART_TRANSMIT)
  69.         uart4_flag_calback = 1;
  70. }
  71.  
  72.  
Tags: STM32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement