Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CAN communication in dsPIC33CK64MP508

Status
Not open for further replies.

surendran_raj

Junior Member level 2
Junior Member level 2
Joined
Aug 8, 2022
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
235
I tried to transmit data using CAN communication in dsPIC33CK64MP508. I use MCC for configuring CAN in dsPIC33CK64MP508 and MCP2551 CAN transceiver. I set the bit rate to 500 kbps. I just transmit two data bytes (0x41 and 0x42) and I used a logic analyzer to view the data but it shows the error.

I have attached my output data using a logic analyzer. Can anyone please correct me?

Code:
int main(void)
{
    // initialize the device
    CAN_MSG_OBJ msg;
    uint8_t data[2] = {0x41,0x42};
    SYSTEM_Initialize();
    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.formatType = CAN_2_0_FORMAT;
            msg.field.brs = CAN_NON_BRS_MODE;
            msg.field.frameType = CAN_FRAME_DATA;
            msg.field.idType = CAN_FRAME_EXT;
            msg.field.dlc = 2;
            msg.data = data;
            
            if(CAN1_IsBusOff() == false)
            {
                if(CAN_TX_FIFO_AVAILABLE == (CAN1_TransmitFIFOStatusGet(CAN1_TX_FIFO1) & CAN_TX_FIFO_AVAILABLE))
                {
                    CAN1_Transmit(CAN1_TX_FIFO1, &msg);
                }
            }
        }
    }
    while (1)
    {
        // Add your application code
    }
    return 1;
}

output in Logic analyzer
Microchip Can logicanalyser.PNG
 

@KlausST
Thanks for your response. I used a logic analyzer to view the transmitted data but it shows a CAN error.
I need to view the transmitted data to check wheater the transmitted data is correct or not.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top