AnsweredAssumed Answered

How can I send more than 3 CAN messages in a row...

Question asked by Stefan Meyre on Dec 26, 2016
Latest reply on Oct 9, 2017 by Franco Spediacci

Hi all; I try to send by CAN bus to 4 individual motor controllers their pwm speed settings in one go. I found out however, that the first three messages go through perfectly, but the forth message got stuck. I can fix this only by adding some delay of 1-2 ms before sending the fourth message;  with is of course terribly ugly to do. How can I solve this? Using STM32F4; see the code below. Thx!

          if (dataToSendByCAN == 1)
          {
               myTxMessage.Data[0] = '#';
               myTxMessage.Data[1] = 'p';
               myTxMessage.Data[2] = 'w';
               myTxMessage.Data[3] = 'm';
               myTxMessage.Data[4] = '2';
               myTxMessage.Data[5] = '/';
               hcan1.pTxMsg = &myTxMessage;
               myTxMessage.DLC = 8;
               myTxMessage.IDE = CAN_ID_STD;
               myTxMessage.ExtId = 0x00;
               myTxMessage.RTR = CAN_RTR_DATA;

               int16_t dummyLong = (uint16_t)(100*(setRPM - outputr - outputp));
               myTxMessage.Data[6] = (uint8_t) dummyLong; //low byte
               myTxMessage.Data[7] = (uint8_t) (dummyLong >> 8);  //high byte
               while (hcan1.State == HAL_CAN_STATE_BUSY);
               myTxMessage.StdId = 0x231;
               HAL_CAN_Transmit_IT(&hcan1);

               dummyLong = (uint16_t) (100*(setRPM - outputr + outputp));
               myTxMessage.Data[6] = (uint8_t) dummyLong; //low byte
               myTxMessage.Data[7] = (uint8_t) (dummyLong >> 8);  //high byte
               while (hcan1.State == HAL_CAN_STATE_BUSY);
               myTxMessage.StdId = 0x233;
               HAL_CAN_Transmit_IT(&hcan1);

               dummyLong = (uint16_t) (100*(setRPM + outputr + outputp));
               myTxMessage.Data[6] = (uint8_t) dummyLong; //low byte
               myTxMessage.Data[7] = (uint8_t) (dummyLong >> 8); //high byte
               while (hcan1.State == HAL_CAN_STATE_BUSY);
               myTxMessage.StdId = 0x232;
               HAL_CAN_Transmit_IT(&hcan1);

               dummyLong = (uint16_t) (100*(setRPM + outputr - outputp));
               myTxMessage.Data[6] = (uint8_t) dummyLong; //low byte
               myTxMessage.Data[7] = (uint8_t) (dummyLong >> 8);  //high byte
               while (hcan1.State == HAL_CAN_STATE_BUSY);
               myTxMessage.StdId = 0x234;
               HAL_Delay(1); //this is soooo ugly!!!
               HAL_CAN_Transmit_IT(&hcan1);

               dataToSendByCAN = 0;

Outcomes