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.
MCU-PLUS-SDK-AM263X: Working on reading all CAN messages and remove filter provided by example code.
Trying to send multiple CAN messages right after each other. But the code only sends the first message if there is no delay between sending messages.
void TorqueCalculationTask(void *pvParameters) { uint64_t throttlePosition = 10; uint64_t steeringPosition = 0; CANMessage rrMessage; CANMessage rlMessage; CANMessage frMessage; CANMessage flMessage; while (1) { // if (xSemaphoreTake(torqueValuesMutex, portMAX_DELAY)) { // readThrottle(); // Read the throttle value at each cycle throttlePosition = throttle_post_transfer; steeringPosition = steering_post_transfer; if (currentState == STATE_READY_TO_DRIVE && !brakePressed) { calculateTorque(throttlePosition, torqueValues, steeringPosition); createAMKCanMessage(0x1234, 1500, torqueValues[frontLeftInv], torqueValues[frontLeftInv+1], flMessage.message); flMessage.id = 0x105; // Set the appropriate CAN ID flMessage.message_length = 8; createAMKCanMessage(0x1234, 1500, torqueValues[frontRightInv], torqueValues[frontRightInv+1], frMessage.message); frMessage.id = 0x106; // Set the appropriate CAN ID frMessage.message_length = 8; createAMKCanMessage(0x1234, 1500, torqueValues[rearRightInv], torqueValues[rearRightInv+1], rrMessage.message); rrMessage.id = 0x107; // Set the appropriate CAN ID rrMessage.message_length = 8; createAMKCanMessage(0x1234, 1500, torqueValues[rearLeftInv], torqueValues[rearLeftInv+1], rlMessage.message); rlMessage.id = 0x108; // Set the appropriate CAN ID rlMessage.message_length = 8; // App_mcanSendCustomMsg(newMsg.id, MESSAGE_TYPE_STANDARD, MCAN_DATA_SIZE_8BYTES, newMsg.message); // if (xSemaphoreTake(canQueueMutex, portMAX_DELAY) == pdTRUE) { xQueueSendToBack(canQueue, &rrMessage, portMAX_DELAY); xQueueSendToBack(canQueue, &frMessage, portMAX_DELAY); xQueueSendToBack(canQueue, &rlMessage, portMAX_DELAY); xQueueSendToBack(canQueue, &flMessage, portMAX_DELAY); xSemaphoreGive(canQueueMutex); // } // } // xSemaphoreGive(torqueValuesMutex); } vTaskDelay(pdMS_TO_TICKS(5)); // Adjust task delay as needed } } void CanMessageSendTask(void *pvParameters) { CANMessage msg; TickType_t lastWakeTime; const TickType_t frequency = pdMS_TO_TICKS(1); while(1){ while (xQueueReceive(canQueue, &msg, portMAX_DELAY)) { vTaskSuspendAll(); App_mcanSendCustomMsg(msg.id, MESSAGE_TYPE_STANDARD, MCAN_DATA_SIZE_8BYTES, msg.message); xTaskResumeAll(); } } } int32_t App_mcanSendCustomMsg(uint32_t msgId, uint8_t msgType, uint8_t dlc, const uint8_t *data) { MCAN_TxBufElement txMsg; uint32_t bufNum = 0U; // Using first buffer for simplicity int32_t status; /* Initialize message to transmit */ MCAN_initTxBufElement(&txMsg); /* Configure message ID based on type */ if (msgType == MESSAGE_TYPE_STANDARD) { txMsg.id = (msgId & MCAN_STD_ID_MASK) << MCAN_STD_ID_SHIFT; // Standard ID txMsg.xtd = FALSE; // Indicating standard identifier } else { txMsg.id = msgId & MCAN_EXT_ID_MASK; // Extended ID txMsg.xtd = TRUE; // Indicating extended identifier } /* Configure DLC */ txMsg.dlc = dlc; /* CAN FD frame format and BRS can be configured based on application needs */ txMsg.fdf = FALSE; // Not a CAN FD frame txMsg.brs = FALSE; // Baud rate switching not used /* Copy data to the message buffer */ for (uint32_t i = 0U; i < gMcanDataSize[dlc] && i < sizeof(txMsg.data); i++) { txMsg.data[i] = data[i]; } /* Write message to Message RAM */ // MCAN_writeMsgRam(gMcanBaseAddr, MCAN_MEM_TYPE_BUF, bufNum, &txMsg); MCAN_writeMsgRam(gMcanBaseAddr, MCAN_MEM_TYPE_FIFO, bufNum, &txMsg); /* Add request for transmission */ status = MCAN_txBufAddReq(gMcanBaseAddr, bufNum); return status; }
Unless I add "vTaskDelay(pdMS_TO_TICKS(1));" after each transmission only the message with id 0x107 (the first one added to the queue) gets sent. Is there a way of sending message after one Tx is complete rather than having to add a manual time delay?
Expected frequency of messages is about 1500Hz so a 1 millisecond delay is not a viable option for me
Hello,
Yes, you should check for transmission completion instead of adding delay. Please explore MCAN_INTR_SRC_TX_FIFO_EMPTY before new transmission.
#define MCAN_INTR_SRC_TX_FIFO_EMPTY (MCAN_IR_TFE_MASK) /**< Tx FIFO Empty interrupt */
Best Regards,
Gunjan