cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I've created a time for one second and transmitting CAN over the one side task. But the CAN message is not transmitted one second once, instead it is transmitting continously with IFS. What might be wrong in my code? please clarify

prashanth.mohan22
Associate III
uint8_t pit_ch1_var=0;
uint32_t pit_ch2_var=0;
 
void pit_ch1_cb(void)
{
	pit_ch1_var = 1;
}
 
void pit_ch2_cb(void)
{
	pit_ch2_var++;
}
 
/*
 * Application entry point.
 */
int main(void) {
 
  CANTxFrame txmsg;
  CANTxFrame txmsg1;
 
	/* Initialization of all the imported components in the order specified in
	 the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
  /* Start PIT driver */
  pit_lld_start(&PITD, pit_config);
  /* Enable PIT Channels */
  pit_lld_channel_start(&PITD, 1U);
  /*
  * Activates the CAN driver 1.
  */
  can_lld_start(&CAND1, &can_config_cfg0);
 
  /*
  * CAN TX Message structure.
  */
  txmsg.IDE = CAN_IDE_STD;
  txmsg.RTR = CAN_RTR_DATA;
  txmsg.LENGTH = 8U;
  txmsg.data32[0] = 0x55AA55AAU;
  txmsg.data32[1] = 0x00000000UL;
 
  txmsg1.IDE = CAN_IDE_STD;
  txmsg1.RTR = CAN_RTR_DATA;
  txmsg1.LENGTH = 8U;
  txmsg1.data32[0] = 0x00000000UL;
  txmsg1.data32[1] = 0x00000000UL;
  /* Application main loop.*/
  while(1)
  {
	  if(pit_ch1_var == 1)
	  {
		pit_ch1_var = 0;
		txmsg.IDE = CAN_IDE_STD;
		txmsg.SID = 0x100;
		while (can_lld_transmit(&CAND1, 1, &txmsg) == CAN_MSG_WAIT) {
		}
 
		txmsg1.SID = 0x100;
		while (can_lld_transmit(&CAND1, 1, &txmsg1) == CAN_MSG_WAIT) {
		}
 
		pal_togglepad(PORT_C,PC_LED8);
	  }
	  else
	  {
		  pal_togglepad(PORT_C,PC_LED7);
	  }
  }
  return 0;
}

How to transmit can as per the cycle time requirements, 10ms, 100ms or 500 ms. Please clarify.

2 REPLIES 2
Erwan YVIN
ST Employee

Hello Prashanth ,

have you solved your issue ?

Best regards

Erwan

prashanth.mohan22
Associate III

Hi Erwan,

Yes, I learned about the behaviour.

Actually, I haven't connected my CAN peripherals to the CAN network, so what happened is, it is not able to sense the bus (Carrier Sense) which produces a bit error and it arbitrates repeatedly to gain access over the bus. (That's the reason for the continuous transmission of CAN Frame). Once I connect the CANH & CANL to CAN peripheral(say Canalyser or CANoe), I'm able to visualize the proper behaviour.

So, I can consider this query as closed.

Thanks & Regards,

Prashanth Mohan