Difficulty with the PIC18F25K80 ECAN and MCC

Thread Starter

hunterage2000

Joined May 2, 2010
487
Hi all,

Has anyone had experience with PIC18F25K80 ECAN and MCC?

I'm having trouble understanding CAN and want to make a simple program to transmit a 8 bytes.

I tried reading the datasheet but the examples don't make sense to me so I tried MCC and the below code but the 8 byte sequence is not showing on the oscilloscope.

Can anyone tell me whats wrong, or point me to a basic example please? Thanks.

Code:
#include "mcc_generated_files/mcc.h"

void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();
    TMR0_Initialize();
    TMR0_StartTimer();
   
    while(1)
    {
        ECAN_Initialize();
        uCAN_MSG txMessage;
        txMessage.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B;
        txMessage.frame.id = 0x100;
        txMessage.frame.dlc = 5;
        txMessage.frame.data0 = 128;
        txMessage.frame.data1 = 64;
        txMessage.frame.data2 = 32;
        txMessage.frame.data3 = 64;
        txMessage.frame.data4 = 128;
        txMessage.frame.data5 = 255;
        txMessage.frame.data6 = 128;
        txMessage.frame.data7 = 64;
   
        CAN_transmit(&txMessage);
    }
}
 

Papabravo

Joined Feb 24, 2006
21,159
You have to wait for the completion of a message before you try to transmit a second message. It has to be ACK'ed by the reciving node. Is your CAN Controller connected to anything? If you have a transceiver and a short piece of cable with a 61 Ω terminator (120Ω || 120Ω ), a lonely node will automatically retry the transmission continuously in the hardware because there is nobody to ACK the transmission. A CAN controller connected to nothing will fault due to a bit error on the first dominant bit and go BUSOFF rather quickly. Check your STATUS registers.
 
Top