sta
tic void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 19200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
huart1.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
以上为配置文件,USART1可以接收数据但发送数据只能发送一个字节,查看ISR状态寄存器EOBF,TXE,TC寄存器都处于置位状态,不知道是什么问题? send_buf[0] = 0x8e; //Í·Âë
send_buf[1] = 0x8e; //Í·Âë
send_buf[2] = 4; //Êý¾Ý³¤¶È
send_buf[3] = Tension_Notch; //ÀÁ¦µµÎ»
send_buf[4] = Weld_time; //ÈÛ½ÓµµÎ»
TxCheckByte = 0;
for (i = 2;i < (send_buf[2] + 1);i++)
{
TxCheckByte = (TxCheckByte^send_buf
);
}
send_buf[5] = TxCheckByte; //УÑéλ
// HAL_UART_Transmit(&huart1,send_buf,6,0xffff);
for (send_len_count = 0;send_len_count < (send_buf[2] + 2);send_len_count++)
{
USART1->TDR = send_buf[send_len_count];
while((USART1->ISR & UART_FLAG_TC)== 0);
}这是发送函数
没有用发送中断,使用查询寄存器方式发送
一周热门 更多>