hello! i m using stm32lo73rz in keil micro vresion 5 in hll format. I cant initialize char and int. I m using unsigned char i[]= "giga" but warning will generate that i not decleared. and when compile the programe in docklight giga will not print correctly any other word will come there at rx side when tx something according to code.this is my email abhij752@gmail.com please help me out from this.
You post makes no sense.
Keil is a standard 'C' compiler:
www.keil.com/.../armcc_chr1359125032122.htm
So there is nothing special about variable initialisation.
Please post a minimum, complete example that illustrates the "problem" - paying attention to the instructions for posting source code to the forum.
Hello Abhi,
I assume you are using this part: www.st.com/.../stm32l073rz.html
And you are using the ARMCC compiler version 5
It sounds like you are used to programming using the C99 programming standard - that is not the default setting in the Keil tools, C90 is.
Project » Options for Target » Compiler on the "C/C++" tab, check "C99 mode"
See: http://www.keil.com/support/man/docs/uv4/uv4_dg_adscc.htm
Otherwise in C90, you must first define your variables then use them.
Here are some of the features the ARMCC compiler supports in the C99 standard.
www.keil.com/.../armcc_chr1359124237277.htm
This is true, but
unsigned char i[]= "giga";
is valid as a definition.
But C90 requires that all definitions must appear before any executable code in a block.
See, for example: stackoverflow.com/.../iso-c90-forbids-mixed-declarations-and-code-in-c
This is why we need to see an example of how that statement is actually being used in context!
Andrew,
Correct. I was making an assumption based on the error message, since it looks like well formed code.
Well, we're all just guessing until the OP comes back and presents a proper example.
I wonder if that will ever happen - or (s)he is just sitting there waiting for replies to her/his email ... ?
Hey Andrew,
Nah, this is probably one of those "post it out of desperation but as soon as you click post, you realized the mistake, but you forgot to tell the rest of us" kind of posts.
I posted a guess to try to avoid this scenario:
https://xkcd.com/979/
#include "main.h" #include "string.h" /* USER CODE BEGIN Includes */ uint8_t rx_byte; char rx_buffer[8]; const uint8_t MSG[]="skit"; /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ static void LL_Init(void); void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); static void MX_I2C1_Init(void); void USART2_IRQHandler(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ LL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); MX_I2C1_Init(); /* USER CODE BEGIN 2 */ LL_USART_ReceiveData8(USART2); LL_USART_EnableRxTimeout(USART2); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ USART2_IRQHandler(); if(rx_byte == 4) { if( strncmp( ( const char* )rx_buffer, ( const char* )MSG, 4 ) == 0 ) { rx_byte=0; unsigned char i[] = "genus"; USART2->TDR = i[4]; USART2->TDR = i[3]; USART2->TDR = i[2]; //LL_USART_TransmitData8(USART2, *i); //LL_USART_TransmitData8(USART2,'e'); //LL_USART_TransmitData8(USART2,i[2]); //LL_USART_TransmitData8(USART2,i[3]); //LL_USART_TransmitData8(USART2,i[4]); //LL_USART_TransmitData8(USART2,i[5]); //LL_USART_TransmitData8(USART2,i[6]); //LL_USART_DisableRxTimeout(USART2); } else { rx_byte=0; LL_USART_TransmitData8(USART2, ('w')); } } if(rx_byte>4) { rx_byte=0; LL_USART_TransmitData8(USART2, 'l'); } if(rx_byte<4 && rx_byte>0) { rx_byte=0; //char i = 'd'; LL_USART_TransmitData8(USART2, 's'); } } //LL_USART_ISR_RTOF; //LL_USART_CR1_RTOIE; //LL_mDelay(1000); LL_GPIO_TogglePin(GPIOA, LL_GPIO_PIN_5); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */
I have given my logic that i have used. Problem occurs that in docklight if i am sending uart(4 char letter) then according to code docklight shows 'w' i.e. is right similarly same with skit. but if i am sending 5 char letter or less than 4 char letter by docklight then docklight shows no response problem is that. Please help me out this problem. And using debug if i open watch window then if i am sending 5 char letter then in watch rx_buffer can't update with 5 char this is also a problem.
thank you so much sir for your help and i have checked c99 is already selected.
You haven't shown the actual error/warning message(s) that you get, and you haven't shown exactly where they occur, but:
{ rx_byte=0; unsigned char i[] = "genus"; USART2->TDR = i[4]; USART2->TDR = i[3]; USART2->TDR = i[2]; //LL_USART_TransmitData8(USART2, *i); //LL_USART_TransmitData8(USART2,'e'); //LL_USART_TransmitData8(USART2,i[2]); //LL_USART_TransmitData8(USART2,i[3]); //LL_USART_TransmitData8(USART2,i[4]); //LL_USART_TransmitData8(USART2,i[5]); //LL_USART_TransmitData8(USART2,i[6]); //LL_USART_DisableRxTimeout(USART2); }
As pointed out in the post of 1-Mar-2018 08:25 GMT, C90 requires that all definitions must appear before any executable code in a block.
The assignment to rx_byte is "executable code" - so the definition of i[] is not allowed (in C90) to come after it.
i have gone project>option for target>c/c++>and then i ticked the c99 block and press ok. so please tell me my complier is c99 or c90. how could i check my complier.
Presumably it was not selected originally, which is why you got the errors - as explained?
But now you are asking a different question:
"if i am sending uart(4 char letter) then according to code docklight shows 'w' i.e. is right similarly same with skit. but if i am sending 5 char letter or less than 4 char letter by docklight then docklight shows no response problem is that"
For a start, your code is hard-coded to send only 3 characters:
USART2->TDR = i[4]; USART2->TDR = i[3]; USART2->TDR = i[2];
So how is that supposed to cope with changing the string length??
But there is a fundamental flaw here:
USART comms are slow relative to the speed of the processor. Therefore, you need to wait for each character to complete transmission before you load the next character!
There will be status bits to tell you when the USART is ready to accept the next character.
Study the processor User Manual for details.
Look at the examples provided by ST.
See: community.st.com/.../46923-stm32l162 for ST tutorials materials.
thank you sir for your suggestion. but please tell me should i put any function which tells that usart ready for the next char. Like-LL_USART_EnableInStopMode,LL_USART_EnableDirectionRx.
#include "main.h" #include "string.h" #include "stdio.h" #include "stm32l0xx.h" /* USER CODE BEGIN Includes */ int rx_byte; char rx_buffer[8] =""; char MSG[]="skit"; int n; static void LL_Init(void); void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); static void MX_I2C1_Init(void); void USART2_IRQHandler(void); //void UART_Write(char data); int main(void) { /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); MX_I2C1_Init(); /* USER CODE BEGIN 2 */ LL_USART_ReceiveData8(USART2); LL_USART_EnableRxTimeout(USART2); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ USART2_IRQHandler(); rx_byte=sizeof(rx_buffer); // n=strlen(rx_buffer); //n=strncmp(rx_buffer,MSG,4); /*if(n==4) {LL_USART_TransmitData8(USART2, ('c')); rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0; break; } else if(n<4) {LL_USART_TransmitData8(USART2, ('w')); rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0; break; } else { LL_USART_TransmitData8(USART2, ('l')); rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0; break; }*/ if(rx_byte == 4) { if( strncmp( ( const char* )rx_buffer, ( const char* )MSG,6 ) == 0 ) { /*unsigned char i[] = "abhishek"; USART2->TDR = i[0]; USART2->TDR = i[1]; USART2->TDR = i[2]; USART2->TDR = i[3]; USART2->TDR = i[4]; USART2->TDR = i[5]; USART2->TDR = i[6]; USART2->TDR = i[7];*/ //printf("correct"); LL_USART_TransmitData8(USART2, ('c')); LL_USART_TransmitData8(USART2, ('o')); LL_USART_TransmitData8(USART2, ('r')); LL_USART_TransmitData8(USART2, ('r')); LL_USART_TransmitData8(USART2, ('e')); LL_USART_TransmitData8(USART2, ('c')); LL_USART_TransmitData8(USART2, ('t')); /*rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0;*/ rx_byte=0; //break; //LL_USART_TransmitData8(USART2, *i); //LL_USART_TransmitData8(USART2,'e'); //LL_USART_TransmitData8(USART2,i[2]); //LL_USART_TransmitData8(USART2,i[3]); //LL_USART_TransmitData8(USART2,i[4]); //LL_USART_TransmitData8(USART2,i[5]); //LL_USART_TransmitData8(USART2,i[6]); //LL_USART_DisableRxTimeout(USART2); } else { rx_byte=0; LL_USART_TransmitData8(USART2, ('w')); /*rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0;*/ } } else if(rx_byte>4) //if(strncmp( ( const char* )rx_buffer, ( const char* )MSG, 4 ) == 1) { rx_byte=0; LL_USART_TransmitData8(USART2, ('l')); /*rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0;*/ } else if(rx_byte<4 && rx_byte>0) //else if(rx_byte==3) { rx_byte=0; //char i = 'd'; LL_USART_TransmitData8(USART2, ('s')); /*rx_buffer [0] =0; rx_buffer [1] =0; rx_buffer [2] =0; rx_buffer [3] =0; rx_buffer [4] =0; rx_buffer [5] =0; rx_buffer [6] =0; rx_buffer [7] =0;*/ } } }
This is my new code in this many of lines are in comment so please don't be confuse. I am trying to send string from docklight and want to compare with 'stm32lo73rz' processor. But by this code if i am sending skit from docklight then then i am getting cr and if sending other 4 letter string then getting w.But if i am sending greater then four letter and less than four letter then at docklight no response.