AnsweredAssumed Answered

Bulk data transfer on CAN bus

Question asked by jagadeesh.puneeth on Nov 13, 2015
Latest reply on Nov 17, 2015 by peacock.jack.003
Hi guys i have managed to communicate using CAN protocol now i want to send around 200 16 bit values from 1 stm32f4 to another stm32f4 below is the code to transfer 8 values, How can i improve my code to transfer 200 values.. can i use same STDID 
void CAN_Txvalues(void) {
            CanTxMsg TxMessage;
  
  
            // transmit */
              TxMessage.StdId = 0x150;
              TxMessage.ExtId = 0x00;
              TxMessage.RTR = CAN_RTR_DATA;
              TxMessage.IDE = CAN_ID_STD;
              TxMessage.DLC = 8;
  
              TxMessage.Data[0] = (ADCDmaValuesc1[0] >> 8) ;
              TxMessage.Data[1] = (ADCDmaValuesc1[0]);
  
              TxMessage.Data[2] = (ADCDmaValuesc1[1] >> 8) ;
              TxMessage.Data[3] = (ADCDmaValuesc1[1]);
  
              TxMessage.Data[4] = (ADCDmaValuesc1[2] >> 8) ;
              TxMessage.Data[5] = (ADCDmaValuesc1[2]);
  
              TxMessage.Data[6] = (ADCDmaValuesc1[3] >> 8) ;
              TxMessage.Data[7] = (ADCDmaValuesc1[3]);
  
              uint8_t TransmitMailbox = 0;
              do
                          {
                              TransmitMailbox = CAN_Transmit( CAN2, &TxMessage );
                          }
                          while( TransmitMailbox == CAN_NO_MB );
                CAN_Txvalues2();// next values
        }
  
void CAN_Txvalues2(void) {
            CanTxMsg TxMessage;
          //  STM_EVAL_LEDOn(LED5);
  
            // transmit */
              TxMessage.StdId = 0x151;
              TxMessage.ExtId = 0x00;
              TxMessage.RTR = CAN_RTR_DATA;
              TxMessage.IDE = CAN_ID_STD;
              TxMessage.DLC = 8;
  
              TxMessage.Data[0] = (ADCDmaValuesc1[4] >> 8) ;
              TxMessage.Data[1] = (ADCDmaValuesc1[4]);
  
              TxMessage.Data[2] = (ADCDmaValuesc1[5] >> 8) ;
              TxMessage.Data[3] = (ADCDmaValuesc1[5]);
  
              TxMessage.Data[4] = (ADCDmaValuesc1[6] >> 8) ;
              TxMessage.Data[5] = (ADCDmaValuesc1[6]);
  
              TxMessage.Data[6] = (ADCDmaValuesc1[7] >> 8) ;
              TxMessage.Data[7] = (ADCDmaValuesc1[7]);
              uint8_t TransmitMailbox = 0;
              do
                          {
                              TransmitMailbox = CAN_Transmit( CAN2, &TxMessage );
                          }
                          while( TransmitMailbox == CAN_NO_MB );
        }
 
void CANrx(void) {
if(stdid =150)
{
save data in adc values 0 to 3
}
if(stdid = 151)
{
save data in adc values 4 to 7
}
}

But i badly need to improve the way my code works.. Any help is most welcome
Thanks guys



Outcomes