how can i solve uart error in iar compiler - Page 1
Forum section: electronics / general

author: ُSTP.Asghari
author_rank: Newbie
timestamp: November 13, 2023, 06:41:39 am
content: Hi everyoneI encounter an error in the iar compiler when entering the following code.Code:#define Enter HAL_UART_Transmit(&huart1,(unsigned char*)E,1,10);#define CR HAL_UART_Transmit(&huart1,(unsigned char*)C,1,10);#define GIM HAL_UART_Transmit(&huart1,(unsigned char*)G,1,10);#define SUB HAL_UART_Transmit(&huart1,(unsigned char*)S,1,10);The error is written in the following line:Code:Error: struct "<unnamed>#35" (declared Hat line 326 of "H:\IAR Codes\3- Sim800\sim800\Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f401xc.h"h) has no field "HAL_UART_Transmit" H:\IAR Codes\3- Sim800\sim800\Core\Src\main.c 207Please tell me why this error occurred and how to solve it. thank you.

author: Psi
author_rank: Super Contributor
timestamp: November 13, 2023, 07:04:45 am
content: This bit looks a bit wrong. Why is there two h.stm32f401xc.h"h)But that may not be your issue.Maybe check stm32f401xc.h and see if it actually has that HAL_UART_Transmit function in it.And check if there's any #if or #ifdef around HAL_UART_Transmit that might not be including it.Also, this isn't the problem but, don't put a ; on the end of your #define's.It may work for a function macro like that, but it breaks things if you want to define numbers and then use them, Like in an array index.You end up with this.. which isnt what you wanted.#define MyNumber 40;MyArray = 1;Becomes..MyArray[40;] = 1;

author: Jeroen3
author_rank: Super Contributor
timestamp: November 13, 2023, 07:21:59 am
content: Please post where you are using those preprocessor directives.struct "<unnamed>#35" is suspect.

author: ُSTP.Asghari
author_rank: Newbie
timestamp: November 14, 2023, 07:50:01 am
content: the problem solved :at line 2 : CR was defined in main and stm32f401xc.h And because of this, the compiler gave an error. I changed CR to CR1 in the main and the problem was solved.

author: radiolistener
author_rank: Super Contributor
timestamp: November 14, 2023, 11:16:59 pm
content: you're needs to make sure that include file containing HAL_UART_Transmit definition is placed before your define which using it

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 15, 2023, 03:44:56 pm
content: Also, macro's are simple text replacement, and not C statements. When defining a macro you should not put an semicolon at the end of the line, because that results in the semicolon being copied too, which results in extra (empty) statements (Which the C compiler accepts without complaining)I don't like the use of such macro's, such short names are too easy to collide in some way. And what is up with those four single character variables (E, C, G and S) as function parameters? Trying to search for them will get many false positives. Personally I never ever use variable names that are shorter then 3 characters, even for temporary local variables. This got confirmed when I used an IDE that can automatically highlight all instances a variable is used, but it required a minimum 3 character length to avoid too many false positives. That is a very nice function to have, both when reviewing unfamiliar code or your own code you have not seen for a few years.