# dsPIC33EV32GM104 CAN bus transmit issue

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_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:

This is my CAN module setting:

This is the pin setting for CAN:

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

This is the CAN analyzer setting:

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

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

• 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? Feb 12 '21 at 12:48
• 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. Feb 13 '21 at 4:20
• 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. Feb 16 '21 at 9:10
• 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. Feb 16 '21 at 11:45
• 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. Feb 17 '21 at 10:14