- }
- }
- void RESEND(u8 cmd,u8 L)//发送内容
- {
- u8 data_send[50];
- u8 cnt = 0;
- u16 i ,sum;
- data_send[cnt++] = title1_send;
- data_send[cnt++] = title2_send;
- data_send[cnt++] = cmd;
- data_send[cnt++] = L;
- for(i=1;i {
- sum += data_send[i];
- }
- data_send[cnt++] = (sum&0xff);
- data_send[cnt++] = ((sum>>8)&0xff);
- data_send[cnt++] = 0X0D;
- data_send[cnt++] = 0X0A;
- USART_send_array(RS485_usart,data_send,cnt-1);
- }
- //发送数组
- void USART_send_array(USART_TypeDef *pUSARTx,u8 *array,u8 len)
- {
- u8 i=0;
- while(i<len)
- {
- USART_SendData(pUSARTx,array[i]);
- while( USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)!= SET);
- i++;
- }
- }
- }
- 配置文件
- void RS485_configure()
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- //配置时钟
- RCC_APB2PeriphClockCmd(RS485_usart_clk,ENABLE);
- RCC_APB2PeriphClockCmd(RS485_USART_RX_GPIO_CLK,ENABLE);
- RCC_APB2PeriphClockCmd(RS485_USART_TX_GPIO_CLK,ENABLE);
- RCC_APB2PeriphClockCmd(RS485_USART_PE_GPIO_CLK,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
- //配置引脚
- GPIO_InitStructure.GPIO_Pin=RS485_usart_TX_PIN;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(RS485_USART_TX_GPIO_PORT,&GPIO_InitStructure);
|