Company code debugging project summary

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/switch_love_case/article/details/88881643

title: Company code debugging project summary
Tags: Siri
DATE: 2019-03-28 23:31:00



Recently the company made a series of projects, I am also responsible for several projects developed in parallel, it is very difficult, very nervous, but fortunately today progress fairly smoothly.

STM32 program written record


Today is the most difficult to debug a 485IC, tomorrow's NBiot debugging M5311 mobile module.

Written procedures did wrong, always wrong but I am also very silent, and finally checked finally get some information, very happy.

Code is recorded as follows:


/***********************************************************
函数名称:int RS485_SendCmd(u8 *cmd,u8 len,int x,int wait)
函数功能:RS485问询与返回指令
入口参数:cmd:问询指令
         len:数据长度
           x:数据起始位
        wait:问询延时
出口参数:数据点
备 注:
***********************************************************/
 
int RS485_SendCmd(u8 *cmd,u8 len,int x,int wait)
{   
  int Val = 0; 
	int i;
	unsigned short CRC_Tmp;
	unsigned short crc;
  struct_usart3.USART_Length = 0;
  printf("[RS485_SendCmd] %d\r\n",len);
	GPIO_SetBits(GPIOB,GPIO_Pin_1);
	delay_ms(2);
  uart3_send_buff(cmd, len);
	delay_ms(2);//稍稍延时一下,原因去查看sp3485的手册吧
	GPIO_ResetBits(GPIOB, GPIO_Pin_1);
  delay_ms(wait);
  if (struct_usart3.USART_Length != 0) //返回值不为空
  {			
      //for(i=0;i<len+1;i++)  //打印出来接收的包共9个数据
      //{
      //printf("%X@",struct_usart3.USART_BUFF[i]);	
      //}	
     // printf("%d",struct_usart3.USART_Length);
		  GPIO_SetBits(GPIOB,GPIO_Pin_1);
		  delay_ms(2);//稍稍延时一下,原因去查看sp3485的手册吧
			crc = ((unsigned short)struct_usart3.USART_BUFF[struct_usart3.USART_Length-2]<<8) + struct_usart3.USART_BUFF[struct_usart3.USART_Length-1]; //收到数据的crc校验值
			CRC_Tmp = CRC_16_HEX(struct_usart3.USART_BUFF,struct_usart3.USART_Length-2); //处理除去最后两位的数据CRC校验,算出crc校验值
			//printf("%X\r\n",crc);
			//printf("%X\r\n",CRC_Tmp);
			if (CRC_Tmp == crc){   //比较CRC校验值是否相等,相等则进行下一步处理
      Val = (struct_usart3.USART_BUFF[x]*256) + (struct_usart3.USART_BUFF[x+1]*1);
			struct_usart3.USART_BUFF[struct_usart3.USART_Length] = '\0'; //清零
			return Val;
			}
			struct_usart3.USART_BUFF[struct_usart3.USART_Length] = '\0'; //清零	
			return Val;
    }  
}

The most important is to enable configuration 485EN ports, and pullup and pulldown when transmitting and receiving data configuration.

    GPIO_SetBits(GPIOB,GPIO_Pin_1);
	delay_ms(2);
    uart3_send_buff(cmd, len);
	delay_ms(2);//稍稍延时一下,原因去查看sp3485的手册吧
	GPIO_ResetBits(GPIOB, GPIO_Pin_1);

"Delay_ms (2);" Delay is very important! ! EN before sending the data first leg pulled up, and then send the data, sending the data to re-EN down into the receive interrupt after receiving the data immediately to ensure that EN is reset (pulled) for the next preparation.

Of this, the company developed a new project the PCB, I have all the code transferred through, for NB debugging and future devices installed debugging, and other sensors for verification.

Guess you like

Origin blog.csdn.net/switch_love_case/article/details/88881643