cancel
Showing results for 
Search instead for 
Did you mean: 

Flex CAN tx problem

Saravanan_Mari
Associate III

Hello,

I am working on a SPC560P Discovery Board.

I have imported test application 'SPC560Pxx RLACAN Test Application for Discovery' for FlexCAN testing. In this FlexCAN0 is used in loop back mode and it is working.

But after disabling loop back mode,I cant see any data on the CAN_TX pin with scope.

I configured the:

  • b[0] as CAN0TXD output and b[1] as CAN0RXD input in the pinmap wizard
  • Disable loopback mode
  • Enable FlexCAN0 Use External Clock
  • Set: PressDive =3 , PropSeg=2 , PSEG1=4 , PSEG2=7

After i start the application the program gets stuck in the transmit while loop:

  1. while (can_lld_transmit(&CAND1,txmailbox, &txmsg)==CAN_MSG_WAIT){
  2. }�?�?�?�?�?�?

Its seems like that thecan_lld_is_tx_empty function returns FALSE and it breaks the can_lld_transmit function.

Is the mailbox needs any additional configuration or I configured the CAN clock incorrectly?

Thanks for your help and sorry for the the lot questions but I am new to 32bit controller programming.

Regards,

Saravanan Mariyappan

21 REPLIES 21
Saravanan_Mari
Associate III

we have been checked the Baud rate for the Both is 1 mb/s and both are little endian only verified with help of datasheet of SPC and STM32 controllers

Saravanan_Mari
Associate III

Please verify the picture for the Baud rate of the Both the Boards

0693W00000AMpncQAD.png

zambrano.luigi
Senior III

Hi Saravan,

the baudrate seems on Pictus seems to be correctly configured to 1M. So, the communication between the 2 boards should be correctly executed. Let me suggest also to try to reduce the baudrate on both boards or, if you have available a second Pictus discovery, to try the communication between the 2 Pictus.

Regards,

Luigi

Saravanan_Mari
Associate III

Hi sir,

Just to highlight again, Can u explain me why this code is stucked in the function can_lld_is_tx_empty function returns FALSE and it breaks the can_lld_transmit function. why it happening

or

Normally When this function will return (can_lld_is_tx_empty function) FALSE and it breaks the can_lld_transmit function.

Saravanan_Mari
Associate III

Hi sir,

Just to highlight again, Can u explain me why this code is stucked in the function can_lld_is_tx_empty function returns FALSE and it breaks the can_lld_transmit function. why it happening

or

Normally When this function will return (can_lld_is_tx_empty function) FALSE and it breaks the can_lld_transmit function.

From my understanding

  1. I think the Transmission Mailbox is not empty that why it not transmitting is my understanding is correct

zambrano.luigi
Senior III

Hi,

in the project that I shared, the can_lld_transmit is invoked within a while cycle that try to transmit a packed using the mailbox 1. If the packet is not received by the receiver (STM32), the mailbox will not return free and, on the next call of the can_lld_transmit, the function can_lld_is_tx_empy will return FALSE. In other words, if the receiver doesn't receive the CAN packet, the next one cannot be sent on the same mailbox. The possible issues can be 1. the pin and CAN configuration (from the Pictus Discovery side, I have provided you a project that included these configuration, so the issue could be on the STM32 side) 2. the baudrate 3. the endianess (as already specified, the PPC is a big endian architecture).

Regards,

Luigi

Saravanan_Mari
Associate III

Hi sir Thanks for the reply,

  1. Our Team verified that STM32 Board is Working with another STM32 controller via CAN we can Communicate
  2. When we connected the SPC and STM32 the Communication is not established
  3. As you mentioned that the sending the data in while(1) whenever the data is received by the receiver then only next data will send Then i have one doubt in receiver side any acknowledgement is send with acknowledgement only sender going to send the next data is this correct?
  4. Can you send you Receiver code with that we can some idea
  5. In our hand we have only one SPC Discovery Board , Then we need to test with STM32 Board only

zambrano.luigi
Senior III

Hi Saravanan,

as explained before, the aim of the project for Pictus Discovery that I shared before is to send some CAN packets through the Pictus CAN transceiver to another board (based on another PowerPC device of the same Pictus family with the same CAN low level driver) that receives the CAN packets from Pictus, converts them in serial packets and transfers them via serial to the host. On the host we have a tool that shows the packets received via serial. In this way we can control the CAN packets sent by the Pictus directly on the host. 

Now, the firmware on the second board that receives the CAN packets from the Pictus Discovery uses the same CAN low level driver used by the Pictus to trasmit the CAN packets. Since the baudrate of the CAN on Pictus Discovery is 1M, the same baudrate is configured also on this second board (please, see the configuration in attachment).

0693W00000AMyYWQA1.pngMoreover, the code used to receive the CAN packets from the Pictus Discovery is the following:

void flexcan1000_Fifo_RX(CANDriver *canp, CANRxFrame crfp) {
 
  data_send(crfp);
  (void) canp;
}
 
void data_send(CANRxFrame crfp) {
 
  uint8_t buffer[18];
  uint8_t i;
  for (i=0;i<18;i++){
  	buffer[i] = 0x00;
  }
  *((uint16_t *)buffer) =  crfp.TIME;
  buffer[2] = crfp.LENGTH;
  buffer[3] = crfp.RTR;
  buffer[4] = crfp.TYPE;
  //buffer += 5;
  *((uint32_t *)&buffer[5]) =  crfp.ID;
  *((uint32_t *)&buffer[9]) =  crfp.data32[0];
  *((uint32_t *)&buffer[13]) =  crfp.data32[1];
  buffer[17] = 0xA4;
  sd_lld_write(&SD1, buffer, 18);
}
 
int main(void) {
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
  /* Start Serial Driver */
  sd_lld_start(&SD1, NULL);
 
  /* Start CAN Driver */
  can_lld_start(&CAND1, &can_config_flexcan1000);
 
 
  /* Application main loop.*/
  for (;;) {
 
  }
}

where flexcan1000_Fifo_RX is the RX callback of the CAN low level driver used to receive the packets from the Pictus Discovery.

Finally, the CAN low level driver used on the second board has been a little bit patched to receive all the packets sent by the Pictus. You can find it in attachment.

Regards,

Luigi

Jde A.1
Associate

Dear Luigi,

I think we are facing the same issue. Where can I find the zip file you refer?

Thank you very much,

José

zambrano.luigi
Senior III

Hi Jose',

please, check the attachment.

Regads,

Luigi