Skip to main content
YBAYR.1
Associate III
February 23, 2023
Question

I'm using NUCLEO64 F302R8 controller, it works when I first debug the program, then it doesn't work at all. What could be the reason for this?

  • February 23, 2023
  • 0 replies
  • 628 views

In my project, I convert char array components to uint_8 data type with atoi. It works fine with my project in the debug phase, then it doesn't work. I have to debug every time I want to run it.

/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	 if(huart->Instance==USART1)
	 {
	 // if the character received is other than 'enter' ascii13, save the data in buffer
	 if(rx_data!=13)//
	 {
	 	buffer[rx_index++]=rx_data;
	 }
	 else
	 {
 
 
			 // if new message arrived, read the message
		 if(sscanf((char*)buffer, "\n+CMTI: " PREF_SMS_STORAGE ",%hhd", &slot)==1)
	 {
	 sprintf(ATcommand,"AT+CMGR=%d\r\n",slot);
	 HAL_UART_Transmit_IT(&huart1,(uint8_t *)ATcommand,strlen(ATcommand));
	 }
	 // if message read contains "ledon", switch the LED ON
	 else if (strstr((char *)buffer,"ledon"))
	 {
	 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 1);
	 sprintf(msj,"Led acildi");
msjDrm=1;
	 }
	 // if message read contains "ledoff", switch the LED OFF
	 else if (strstr((char *)buffer,"ledoff"))
	 {
	 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 0);
	 sprintf(msj,"Led kapandi");
msjDrm=1;
	 }
	 // This will delete all messages in the SIM card. (Is it ok for you?)
	 else if (strstr((char *)buffer,"READ"))
	 {
	 sprintf(ATcommand,"AT+CMGD=,4\r\n");
	 HAL_UART_Transmit_IT(&huart1,(uint8_t *)ATcommand,strlen(ATcommand));
	 }
	 else
	 {
 
	 	 /************* ayarlamLAR *************/
 
	 	 	 char destination[25];
	 	 	 int start = 1;
	 	 	 int len = 2;
	 	 	 substring(destination, (char *)buffer, start, len);
 
	 	 if (strstr((char *)destination,"ch"))
	 	 	 {
 
	 		 /***********kanal************/
	 		 	veri[0]=buffer[3];
	 		 	veri[1]=buffer[4];
	 		 kanal = (uint8_t)atoi(veri);
 
 
	 		 /***********adres************/
	 		 	veri[0]=buffer[5];
	 		 	veri[1]=buffer[6];
	 		 	adres = (uint8_t)atoi(veri);
 
	 		 	/*****hangı cıkıs?******/
	 		 	veri[0]=buffer[7];
	 		 	veri[1]=buffer[8];
	 		 	cikis_ = (uint8_t)atoi(veri);
 
 
	 	 	 if (cikis_== 1)
	 	 	 {
 
 
	 	 		veri[0]=buffer[9];
	 	 		veri[1]=buffer[10];
	 	 		drm = (uint8_t)atoi(veri);
 
	 	 		veri[0]=buffer[11];
	 	 		veri[1]=buffer[12];
	 	 		baslangic_h = (uint8_t)atoi(veri);
 
 
	 	 		veri[0]=buffer[13];
	 	 		veri[1]=buffer[14];
	 	 		baslangic_m = (uint8_t)atoi(veri);
 
	 	 		veri[0]=buffer[15];
	 	 		veri[1]=buffer[16];
	 	 		bitis_h = (uint8_t)atoi(veri);
 
 
	 	 		veri[0]=buffer[17];
	 	 		veri[1]=buffer[18];
	 	 		bitis_m = (uint8_t)atoi(veri);
 
	 	 	 }
 
 
	 	 	 	 	 	 	 	 	 Tx_data[0]=0x00;//başlangıc biti
	 	 		 	 	 				Tx_data[1]=adres;//adress
	 	 		 	 	 				Tx_data[2]=kanal;// kanal
	 	 		 	 	 				Tx_data[3]=drm;//0
	 	 		 	 	 				Tx_data[4]=baslangic_h;
	 	 		 	 	 				Tx_data[5]=baslangic_m;
	 	 		 	 	 				Tx_data[6]=bitis_h;
	 	 		 	 	 				Tx_data[7]=bitis_m;//0
	 	 		 	 	 				Tx_data[8]=8;
	 	 		 	 	 				Tx_data[9]=9;
	 	 		 	 	 				Tx_data[10]=9;
	 	 		 	 	 				Tx_data[11]=9;//0
	 	 		 	 	 				Tx_data[12]=9;
	 	 		 	 	 				Tx_data[13]=9;
	 	 		 	 	 				Tx_data[14]=9;
	 	 		 	 	 				Tx_data[15]=8;//0
	 	 		 	 	 				Tx_data[16]=8;
	 	 		 	 	 				Tx_data[17]=8;
	 	 		 	 	 				Tx_data[18]=8;
	 	 		 	 	 				Tx_data[19]=7;//0
	 	 		 	 	 				Tx_data[20]=7;
	 	 		 	 	 				Tx_data[21]=7;
	 	 		 	 	 				Tx_data[22]=7;
	 	 		 	 	 				Tx_data[23]=7;//0
	 	 		 	 	 				Tx_data[24]=7;
	 	 		 	 	 				Tx_data[25]=7;
	 	 		 	 	 				Tx_data[26]=7;
	 	 		 	 	 				Tx_data[27]=7;//0
	 	 		 	 	 				Tx_data[28]=7;
	 	 		 	 	 				Tx_data[29]=7;
	 	 		 	 	 				Tx_data[30]=7;
	 	 		 	 	 				Tx_data[31]=7;//0
	 	 		 	 	 				Tx_data[32]=7;
	 	 		 	 	 				Tx_data[33]=7;
	 	 		 	 	 			 // HAL_UART_Transmit(&huart3, Tx_data, sizeof(Tx_data), 100);
	 		 sprintf(msj,"YAZDIRILDI");
	 	 	 	 msjDrm=1;
 
	 	 	 }
 
 
	 }
 
	 rx_index=0;
	 memset(buffer,0,sizeof(buffer));
 
	 }
 
	 }
 
	 // Enabling interrupt receive again
			 		 HAL_UART_Receive_IT(&huart1,&rx_data,1); // receive data (one character only)
 
 
}
/* USER CODE END 4 */

This topic has been closed for replies.