@香水城
香版主你好,我在用STM32F103在做串口是能发送一次数据包,第二次数据包就发送不了了。
我是用STM32CubeMX导出的工程。
数据包如下。
void USC512C_SendSetupData1(UART_HandleTypeDef *huart,uint8_t ch, uint16_t IcNum)
{
uint8_t i;
uint8_t *da;
if(ch==1) da = ICDATA11;
else if(ch==2) da = ICDATA21;
else da = ICDATA41;
//Set reset 0 times 2s
__HAL_UART_DISABLE(huart);
//__HAL_UART_ENABLE(huart);
HAL_GPIO_WritePin(PB10_OutPin_GPIO_Port, PB10_OutPin, GPIO_PIN_RESET);
HAL_TIM_Base_Start_IT(&htim6);
while(flag2s); //调试时停在第二次的这儿过不去了。
flag2s = 1;
printf(">>> Set IC 2s reset OK ......\r\n");
//8us高电平
HAL_GPIO_WritePin(PB10_OutPin_GPIO_Port, PB10_OutPin, GPIO_PIN_SET);
delayXus(8);
//发送Start Code 0x00;
//__HAL_UART_DISABLE(huart);
__HAL_UART_ENABLE(huart);
HAL_UART_Transmit(huart,(uint8_t*)DATA0,1,0xff);
//等待发送完毕
while(__HAL_UART_GET_FLAG(huart,UART_FLAG_TC)!=SET);
printf(">>> Set IC send Start Code 0x00 OK ......\r\n");
//send Heigh "W" W>176us;
__HAL_UART_DISABLE(huart);
//__HAL_UART_ENABLE(&huart3);
HAL_GPIO_WritePin(PB10_OutPin_GPIO_Port, PB10_OutPin, GPIO_PIN_SET);
delayXus(176);
printf(">>> Set IC 'W' OK ......\r\n");
for(i=0; i<IcNum; i++)
{
//发送11位数据
//__HAL_UART_DISABLE(&huart3);
__HAL_UART_ENABLE(huart);
HAL_UART_Transmit(huart,(uint8_t*)da,11,0xff);
//等待发送完毕
while(__HAL_UART_GET_FLAG(huart,UART_FLAG_TC)!=SET);
//send Heigh "W" W>176us;
__HAL_UART_DISABLE(huart);
//__HAL_UART_ENABLE(huart);
HAL_GPIO_WritePin(PB10_OutPin_GPIO_Port, PB10_OutPin, GPIO_PIN_SET);
delayXus(176);
}
printf(">>> IC data updata1 OK ......\r\n");
}
主函数调用如下:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_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_USART3_UART_Init();
MX_TIM3_Init();
MX_TIM2_Init();
MX_TIM6_Init();
MX_TIM7_Init();
MX_USART1_UART_Init();
/* Initialize interrupts */
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
BSP_Data_Init();
USC512C_SendSetupData1(&huart3,2, 100); //第一个可以发送。
USC512C_SendSetupData2(&huart3,2, 100); //第二个就发送不了了。除了数据不一样,其他都与第一个一样。
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
调试的时候在发送函数的定时器处,红色标记的地方,过不去了。
|