Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * RTG.c
- *
- *
- *
- */
- #include "../../TESTING/Inc/UART.h"
- uint8_t uart5_flag_calback = 0; //Flag when UART completes receiving data from user
- uint8_t uart4_flag_calback = 0;
- uint8_t uart5_flag_h = 0;
- void UART_main() {
- UART_send(20,(uint8_t*)"some_data",10);
- UART_receive(20,(uint8_t*)"",10);
- // 4->2 old
- // 4->5 new 4tx -> 5rx
- // 5->4 new_2 5tx -> 4rx
- }
- //todo: clear buffer
- //todo: add it in case of failure
- void UART_send(uint8_t data_size,uint8_t *data_sent,uint8_t iteration) {
- uint8_t buffer[data_size];
- printf("Start of program:\r\n");
- HAL_UART_Receive_DMA(UART_RECEIVE, buffer, data_size);
- HAL_Delay(100);
- HAL_UART_Transmit(UART_TRANSMIT, data_sent, data_size,
- TIMEOUT_TIME);
- while (--iteration) {
- if (uart5_flag_calback) {
- HAL_UART_Receive_DMA(UART_RECEIVE, buffer, data_size);
- printf("Data_sent: %s\r\n", buffer);
- uart5_flag_calback = 0;
- HAL_UART_Transmit(UART_TRANSMIT, data_sent, data_size,
- TIMEOUT_TIME);
- HAL_Delay(DELAY_TIME);
- }
- }
- }
- void UART_receive(uint8_t data_size,uint8_t *data_sent,uint8_t iteration) {
- uint8_t buffer[data_size];
- printf("Start of program:\r\n");
- HAL_UART_Receive_DMA(UART_TRANSMIT, buffer, data_size);
- HAL_Delay(100);
- HAL_UART_Transmit(UART_RECEIVE, data_sent, data_size,
- TIMEOUT_TIME);
- while (--iteration) {
- if (uart5_flag_calback) {
- HAL_UART_Receive_DMA(UART_RECEIVE, buffer, data_size);
- printf("Data_Received: %s\r\n", buffer);
- uart4_flag_calback = 0;
- HAL_UART_Transmit(UART_RECEIVE, data_sent, data_size,
- TIMEOUT_TIME);
- HAL_Delay(DELAY_TIME);
- }
- }
- }
- void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
- if (huart == UART_RECEIVE)
- uart5_flag_calback = 1;
- if (huart == UART_TRANSMIT)
- uart4_flag_calback = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement