本帖最后由 穿西装的强子 于 2025-1-20 10:48 编辑
由于该评估板暂无多余的io接出到串口,只能手动改板子飞线了;
先确定IO,反向电动势接口在代码上暂时没使用,接的引脚是PC4和PC5,把这个地方改到串口1使用;
根据数据手册,PC4和PC5使用AF2作为串口;
代码如下,把printf打印也加上:
void IOinit_uart1(void)
{
GPIO_Config_T GPIO_InitStructure;
/* PF0 -> uart1_tx */
GPIO_InitStructure.pin = GPIO_PIN_4;
GPIO_InitStructure.speed = GPIO_SPEED_50MHz;
GPIO_InitStructure.mode = GPIO_MODE_AF;
GPIO_InitStructure.pupd = GPIO_PUPD_NO;
GPIO_InitStructure.outtype = GPIO_OUT_TYPE_PP;
GPIO_Config(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.pin = GPIO_PIN_5;
GPIO_Config(GPIOC, &GPIO_InitStructure);
GPIO_ConfigPinAF(GPIOC, GPIO_PIN_SOURCE_4, GPIO_AF_PIN2);
GPIO_ConfigPinAF(GPIOC, GPIO_PIN_SOURCE_5, GPIO_AF_PIN2);
}
int fputc(int ch, FILE* f)
{
/* send a byte of data to the serial port */
USART_TxData(USART1, (uint8_t)ch);
/* wait for the data to be send */
while (USART_ReadStatusFlag(USART1, USART_FLAG_TXBE) == RESET);
return (ch);
}
void Pilot_uart_init(void)
{
USART_Config_T USART_InitStructure;
DMA_Config_T DMA_InitStructure;
// RCM_ConfigUSARTCLK(RCM_USART1CLK_SYSCLK);
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_USART1);
USART_InitStructure.baudRate = 115200;//1945946;
USART_InitStructure.mode = USART_MODE_TX_RX;
USART_InitStructure.hardwareFlowCtrl = USART_FLOW_CTRL_NONE;
USART_InitStructure.parity = USART_PARITY_NONE;
USART_InitStructure.stopBits = USART_STOP_BIT_1;
USART_InitStructure.wordLength = USART_WORD_LEN_8B;
USART_Config(USART1,&USART_InitStructure);
USART_DisableOverSampling8(USART1);
USART_DisableOneBitMethod(USART1);
USART1->CTRL3 &= (uint32_t)~0x400;
/** Enable USART */
USART_Enable(USART1);
USART_EnableDMA(USART1, USART_DMA_REQUEST_TX);
USART_EnableDMA(USART1, USART_DMA_REQUEST_RX);
/* USART1_RX Init */
DMA_InitStructure.direction = DMA_DIR_PERIPHERAL;
DMA_InitStructure.peripheralInc = DMA_PERIPHERAL_INC_DISABLE;
DMA_InitStructure.memoryInc = DMA_MEMORY_INC_ENABLE;
DMA_InitStructure.peripheralDataSize = DMA_PERIPHERAL_DATASIZE_BYTE ;
DMA_InitStructure.memoryDataSize = DMA_MEMORY_DATASIZE_BYTE ;
DMA_InitStructure.circular = DMA_CIRCULAR_DISABLE ;
DMA_InitStructure.priority = DMA_PRIORITY_LEVEL_LOW;
DMA_Config(DMA_CHANNEL_5, &DMA_InitStructure);
/* USART1_TX Init */
DMA_InitStructure.direction = DMA_DIR_MEMORY;
DMA_InitStructure.peripheralInc = DMA_PERIPHERAL_INC_DISABLE;
DMA_InitStructure.memoryInc = DMA_MEMORY_INC_ENABLE;
DMA_InitStructure.peripheralDataSize = DMA_PERIPHERAL_DATASIZE_BYTE ;
DMA_InitStructure.memoryDataSize = DMA_MEMORY_DATASIZE_BYTE ;
DMA_InitStructure.circular = DMA_CIRCULAR_DISABLE ;
DMA_InitStructure.priority = DMA_PRIORITY_LEVEL_LOW;
DMA_Config(DMA_CHANNEL_4, &DMA_InitStructure);
}
硬件改线如下,黄色是PC4-TX,橙色是PC5-RX:
使用py+qt的串口调试工具进行波形显示,链接如下:使用python+qt做一个串口波形调试工具 - 电子设计论坛 - 21ic电子技术开**坛https://bbs.21ic.com/icview-3427892-1-1.html
显示了4个波形,q轴,d轴当前电流,q轴d轴设置电流,该波形是启动时电流变化,可以看到,q轴电流在启动时有个大电流,按资料显示,启动时因为无编码器,不知道内部电角度,只有通过q轴电流强拉启动,有转速或者q轴到0°时初始化电角度,再通过滑模观测器进行电角度的观测换算。
|