0
\$\begingroup\$

I created a a CAN transmit project for the dsPIC33EV32GM104 using the MCC plugin. I used the example program given in can1.h.

When I try to debug and check the functionality of the CAN bus I am getting stuck in the CAN1_transmit function which returns the status CAN_TX_MEG_REQUEST_BUFFER_FULL.

So, I can't get any output in my CAN analyzer terminal window. The dsPIC runs at 40MIPS. I am using a CAN bus analyzer from Microchip to receive the data from an MCP2561 transceiver. The CAN bitrate is set at 250 Kbps. This is my code:

#include "mcc_generated_files/system.h"
#include "mcc_generated_files/can1.h"
#include <stdio.h>
#include <libpic30.h>

int main(void)
{
  CAN_MSG_OBJ msg;
  uint8_t data[8] = {0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48};
  SYSTEM_Initialize();
  CAN1_TransmitEnable();
  CAN1_ReceiveEnable();
  CAN1_OperationModeSet(CAN_CONFIGURATION_MODE);
   
  if (CAN_CONFIGURATION_MODE == CAN1_OperationModeGet())
  {
    if (CAN_OP_MODE_REQUEST_SUCCESS == CAN1_OperationModeSet(CAN_NORMAL_2_0_MODE))
    {
      msg.msgId = 0x1FFFF;
      msg.field.frameType = CAN_FRAME_DATA;
      msg.field.idType = CAN_FRAME_EXT;
      msg.field.dlc = CAN_DLC_8;
      msg.data = data;
              
      while(1)
      {
        if (CAN1_IsBusOff() == false)
        {
          CAN1_Transmit(CAN_PRIORITY_HIGH, &msg);
          if (CAN1_IsTxErrorWarning() == true)
          {
            break;
          }
        }
      }
    }
  }
}

This is my primary clock setting:

enter image description here

This is my CAN module setting:

enter image description here

enter image description here

This is the pin setting for CAN:

enter image description here

This is the debug info about the CAN transmit message status:

enter image description here

This is the CAN analyzer setting:

enter image description here

This is CAN1.c (MCC plugin generated file) uploaded to GitHub:

https://github.com/vijayakumar-sargunam/CAN-TX-RX/blob/main/can1.c

\$\endgroup\$
9
  • 1
    \$\begingroup\$ All CAN nodes will need someone to speak with or they get sad. Tx buffer overrun indicates that this might be the case. Your listener is likely set to a passive mode. Also see What are the most common causes of CAN bus communication errors? \$\endgroup\$
    – Lundin
    Feb 12 '21 at 12:48
  • \$\begingroup\$ Thanks for the link you shared very informative. If i remove the while(1) and CAN1_IsTxErrorWarning() in the main function and debug the code the Tx buffer overrun is not present and CAN_TX_MSG_REQUEST_SUCCESS is enabled and messageSent flag becomes 1(success). but i did receive any message in my CAN bus analyzer terminal screen. \$\endgroup\$
    – V_J viji
    Feb 13 '21 at 4:20
  • 1
    \$\begingroup\$ No wonder you get a Tx overflow then. Maybe you've managed to set the controller in "loopback" mode or some such - I can't help you troubleshooting "clickycheckboxware"... If there's actual C code I could perhaps help, though I haven't used this particular CAN controller before. I would suspect pin routing to be the most likely culprit though. \$\endgroup\$
    – Lundin
    Feb 16 '21 at 9:10
  • 1
    \$\begingroup\$ You're gonna have to single step the CAN initialization in your debugger and check that all registers get set as expected. But as noted, always suspect pin routing too, which will probably be some other registers. \$\endgroup\$
    – Lundin
    Feb 16 '21 at 11:45
  • 1
    \$\begingroup\$ Hi Lundin finally i got the output in CAN analyzer window. As you correctly suggested problem is with pin configuration. For CAN_TX i set the initial condition of the pin in start high mode that's why i got high value always on the CAN transmit pin. once i remove the start high option for C1TX pin the CAN module starts working. Thanks for your support. \$\endgroup\$
    – V_J viji
    Feb 17 '21 at 10:14
1
\$\begingroup\$

The problem with the CAN transmit is in the pin settings. I initially set the CAN TX pin in start high mode. when i try to transmit the CAN data from the controller i always get high value on the pin. As suggested by Mr.Lundin i checked the pin setting once again and i experimentally removed the start high option for C1TX (CAN transmit pin - refer the pin setting image above).And the CAN module starts transmitting. Thanks to Mr.Lundin for pin pointing the issue.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.