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.
#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.
and it has exactly the same flaws as pointed out in the previous code - only now repeated more often !!
This has honestly got to be the most brain damaged code I've seen in a long while. I'm not as confused as I am distressed with the logic.
When you do sizeof() of buffer thats 8 bytes long it is never going to return 4, even for very small values of 8.
You can't compare a 4 character string 6 bytes at a time. It will never match.
You can't blindly write multiple character to the TDR register.
Why do you call the IRQ Handler in the loop? What does the code in the IRQ Handler look like or do?
Perhaps try something simpler that is within your grasp, like reading characters and echoing them back, or changing the case.
Sir Andrew Neil, I am begginer for the stm32lo73rz and keil. I can't understand how its works.I read some datasheets but still some basic error generate in my code. Please tell how could i resolve the problem correctly and excatly. I know what's the problem but i don't know that how to solve this. Please help me.
This is i am using new code but output will not come.how to solve this problem.
/* Includes ------------------------------------------------------------------*/ #include "main.h" #include "string.h" #include "stdio.h" #include "stm32l0xx.h" /* USER CODE BEGIN Includes */ char rx_buffer[8] =""; char MSG[]="skit"; int n; /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ //UART_HandleTypeDef huart2; /* 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); /* 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(); /* Configure the system clock */ SystemClock_Config(); MX_GPIO_Init(); MX_USART2_UART_Init(); MX_I2C1_Init(); LL_USART_ReceiveData8(USART2); LL_USART_EnableRxTimeout(USART2); while (1) { n=strcmp(rx_buffer, MSG); if( n== 0 ) { LL_USART_TransmitData8(USART2, ('c')); rx_buffer[0x00]=0x00; } else if(n>4) { LL_USART_TransmitData8(USART2, ('l')); rx_buffer[0x00]=0x00; } else { LL_USART_TransmitData8(USART2, ('s')); } } }
Still a lot of critical code that simply isn't been shown, despite being asked.
Perhaps try something simple within your grasp, without interrupts or strings
/* Includes ------------------------------------------------------------------*/ #include "main.h" #include "string.h" #include "stdio.h" #include "stm32l0xx.h" /* 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); /* USER CODE END 0 */ void putstring(char *s) { while(*s) { /* Wait for TXE flag to be raised */ while (!LL_USART_IsActiveFlag_TXE(USART2)); /* Write character in Transmit Data register. TXE flag is cleared by writing data in TDR register */ LL_USART_TransmitData8(USART2, *s++); } } int main(void) { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ LL_Init(); /* Configure the system clock */ SystemClock_Config(); MX_GPIO_Init(); MX_USART2_UART_Init(); // code not shown, don't enable interrupts putstring("Hello World!\n"); while(1) { if (LL_USART_IsActiveFlag_RXNE(USART2)) /* character ready */ { uint8_t ch = LL_USART_ReceiveData8(USART2); /* read it */ /* Wait for TXE flag to be raised */ while (!LL_USART_IsActiveFlag_TXE(USART2)); /* Write character in Transmit Data register. TXE flag is cleared by writing data in TDR register */ LL_USART_TransmitData8(USART2, ch); } if (LL_USART_IsActiveFlag_NE(USART2) LL_USART_ClearFlag_NE(USART2); if (LL_USART_IsActiveFlag_FE(USART2) LL_USART_ClearFlag_FE(USART2); if (LL_USART_IsActiveFlag_PE(USART2) LL_USART_ClearFlag_PE(USART2); } }
Rather than just leaping in with both feet straight into the deep end, perhaps it would be more productive to take a more structured approach?
Attend an instructor-led course.
Get a good book that will start you at the basics, and work up from there.
http://www.keil.com/books/
Hello Abhi,
It appears you got your code to link, but you are now running into issues using the the STM32 Low level libraries.
Are you using the CubeMX tools to generate your code? If so, make sure you are using the latest version of the CubeMX libraries for the STM32L0.
I would suggest cross posting on the ST forum - you would find more sample code listing there, and it might help you with your own code.
For example:
community.st.com/.../42107-stm32f7-haluartreceiveit-revisited
community.st.com/.../183403-re-stm32-115200-uart-and-missing-data
Or search the web for sample code:
innomatic.blogspot.com/.../uart-data-communication-in-stm32cube.html
If you're going to cross post, then be sure to:
1. In your new post, give a link to this thread - so that people can see what's already been said & done.
2. In this post, give a link to your new post.