主题中讨论的其他器件:MOTORWARE
工具与软件:
你(们)好
"我已经开始使用 UART 命令来运行电机。 我将在 MotorWare 中使用 Lab11、并已在 HAL 教程的第6.7节中添加了 SCI/UART。 我的问题是、如何编写电机启动和停止功能的逻辑? "怎么会这样?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
你(们)好
"我已经开始使用 UART 命令来运行电机。 我将在 MotorWare 中使用 Lab11、并已在 HAL 教程的第6.7节中添加了 SCI/UART。 我的问题是、如何编写电机启动和停止功能的逻辑? "怎么会这样?
嗨、Yanming Luo
"我已经在 main.h 文件中写入了 handleMotorCommands。 如果需要任何修改、请告诉我。"
In main.h file void handleMotorCommands(void) { // Start/Stop the motor based on isMotorOn flag if (isMotorOn) { gMotorVars.Flag_Run_Identify = true; printf("Motor is ON\n"); // Debug: Print motor state } else { gMotorVars.Flag_Run_Identify = false; printf("Motor is OFF\n"); // Debug: Print motor state } // Set the target running speed gMotorVars.SpeedRef_krpm = targetSpeed; printf("Target speed set to %ld krpm\n", gMotorVars.SpeedRef_krpm); // Debug: Print target speed }
嗨、Yanming Luo
"我已写入 main.c 文件。 如果需要任何修改、请告诉我。"
In main.c file // UART Rx ISR interrupt void sciARxISR(void) { HAL_Obj *obj = (HAL_Obj *)halHandle; while (SCI_rxDataReady(obj->sciAHandle)) { char c = SCI_read(obj->sciAHandle); if (counter < BUF_SIZE - 1) // -1 to leave space for null terminator { buf[counter++] = c; if (c == '>') // End of command { buf[counter] = '\0'; // Null-terminate the command string processCommand(buf); counter = 0; // Reset buffer index } } else { // Buffer overflow, reset counter counter = 0; } } // Clear SCI interrupt flag PIE_clearInt(obj->pieHandle, PIE_GroupNumber_9); } // Process received command void processCommand(char *command) { if (strcmp(command, CMD_RX_ON) == 0) { isMotorOn = true; sendResponse("Motor ON"); } else if (strcmp(command, CMD_RX_OFF) == 0) { isMotorOn = false; sendResponse("Motor OFF"); } else { sendResponse("Unknown Command"); } } // Send response to UART void sendResponse(const char *message) { int length = strlen(message); returnBuf[0] = '<'; strncpy(&returnBuf[1], message, length); returnBuf[length + 1] = '>'; serialWrite(returnBuf, length + 2); } // Write data to UART void serialWrite(const char *sendData, int length) { int i = 0; GPIO_setHigh(halHandle->gpioHandle, GPIO_Number_12); while (i < length) { if (SCI_txReady(halHandle->sciAHandle)) { SCI_write(halHandle->sciAHandle, sendData[i]); i++; } } isWaitingTxFifoEmpty = true; }
如果 您在添加 SCI 方面有任何疑问、可以查看如下所示 MotorWare 文件夹中的 HAL 用户指南、并参阅"6.7"章节。 通过 Motorware 中的 InstaSPIN 向项目添加 SCI/UART 功能。
motorware_hal_tutorial.pdf、位于"\ti\motorware\motorware_1_01_00_18\docs\tutorware\hal_tutorial.pdf"