It would make more sense to pick an actual CAN controller or alternatively a processor with an embedded CAN controller. The problem with pseudo code is that it can be written but it CANNOT be tested. IMHO it is nearly useless.What do you think about post #18 ?
Can we make any progress with pseudo code
Check to see if your microcontroller CAN module has loopback mode. Most do for just this sort of testing.I was eager to learn about the CAN protocol through experimentation. However, I lack the necessary hardware to conduct the experiment. Although I have a microcontroller with built-in CAN functionality, I've realized that it's not sufficient alone. To properly perform the experiment, I require an additional transceiver IC, which unfortunately I don't have. There are also some constraints preventing me from purchasing new hardware.
This is reason I am asking theoretically question and tring to understand CAN message with basic application like LED control

Yes please, I'm interestedIf you want, I can take you through your particular application using the CAN controller on the T89C51CC01.
In luck, I have a old (uncompleted project


Nice!In luck, I have a old (uncompleted project) with a K80 on it and a old software project that can be easily patched to test CAN.
void produceIO(void)
{
SET_PROD_IO_SIZE(g_PollProdSize) ;
/***** Determine XMT_BUF[] availability *****/
if((CANEN2 & TxPollInt) == 0)
CANPAGE = TxPoll ;
CANCONCH = 0 ;
/***** Produce for the POLLED I/O cnxn *****/
if(dnetObj.alloc_choice & POLLED)
{
/***** Load the IDENTIFIER *****/
CANIDT1 = ((POLL_RESPONSE << 3) | (dnetObj.macId >> 3));
CANIDT2 = (dnetObj.macId << 5);
CANIDT4 = 0 ;
POLL_PRODUCE_ASSEMBLY ;
}
else if ((dnetObj.alloc_choice & ACK_SUPPRESS) == 0)
{
/**** Change of State from Master or zero-length ack - POLL_RSP is also a cos ack msgid ****/
CANIDT1 = ((POLL_RESPONSE << 3) | (dnetObj.macId >> 3)) ;
CANIDT2 = (dnetObj.macId << 5) ;
CANIDT4 = 0 ;
CANCONCH = TxRequest + NULL_MESSAGE_LEN ;
}
g_cnxnProduce.1 = NO_WAITING_PRODUCER ;
}
else
{
/***** The CAN transmitter must be busy *****/
if(g_cnxnProduce.1 == NO_WAITING_PRODUCER)
{
/***** Point to the I/O connection instance that is to produce *****/
g_cnxnProduce.1 = WAITING_PRODUCER ;
}
}
}
#define POLL_PRODUCE_ASSEMBLY \
{ \
/***** Load the xmt buffer with the POLL Data *****/ \
CANMSG = pollCnxn_p_data[0] ; \
CANMSG = pollCnxn_p_data[1] ; \
CANCONCH = TxRequest + g_PollProdSize ; \
}


#include "mcc_generated_files/ecan.h"
uint8_t leds1 = 0x13, leds2 = 0x37; // some random data that could be LED on/off bits in a byte
uCAN_MSG txMessage;
case APP_CONNECT:
txMessage.frame.idType = dSTANDARD_CAN_MSG_ID_2_0B;
txMessage.frame.id = 0x120;
txMessage.frame.dlc = 2;
txMessage.frame.data0 = leds1++;
txMessage.frame.data1 = leds2++;
CAN_transmit(&txMessage);
appData.state = APP_COMMUNICATE;
break;
I've got a few CAN projects for 8-bt micros to 64-bit Linux machines but only one old PIC18F45K80 prototype from an project to automate direct-drive motor resolver setup and programming.Nice!
How many CAN controller do you have? Do you have two PIC18F45K80?
What was your first experiment to learn CAN protocol?
Thank you masked man!...
Listen to @Papabravo. He is a real expert.
Receiver node is part of the APPLICATION LAYER, such as J1939 or NMEA2000.I spent some time on reading CAN protocol documents and discussions read many times, but I'm still struggling to understand with three points with one example. Let's imagine a CAN network with two nodes: one node sending a message to control an LED connected on the other node. For explanation purposes, You can consider your choice of microcontroller and the CAN trans receiver IC for the reference to the explanation. it may be save your time and if you want me to show the specific microcontroller and trans receiver IC. I'll refer to the PIC18F45K80 as the microcontroller and the MCP2515 as the transceiver IC.
Three points In this context:
1. Determining Receiver Node ID:
I've been searching through the MCP2515 datasheet, but I couldn't find information on how to determine the receiver node ID. How can we find or specify this ID for inclusion in the CAN message frame.
2. Data Bytes Required:
To control the LED (turning it on/off), would we need one byte or two?
I'm thinking one byte could turn it on and another could turn it off, but I'm uncertain. Could you clarify this?
3. Configuring CRC Field: Regarding error management in the CRC field, I'm unclear about the specific value needed for error monitoring. Could you provide guidance on what value should be set for effective error management in my application specific?
@Papabravo
1. Node Id assignment is completely arbitrary and is not defined by the standards. In practice we used DIP switches, or non-volatile memory. In an 8-pin package we used two switches to determine the bit rate and six switches to determine the node ID (we called it MAC Id, an acronym for Media Access Control). The bit rates were 125 kbps, 250 kbps, and 500 kbps. The total number of MAC addresses was 64. The DIP switch would be read at power up and used to initialize the node. As part of the initialization procedure each node would broadcast its address to see if there were duplicates. A client device could either create a list of nodes on the network or have a list of nodes that are known and/or expected to be on the network. In our case the MAC Id would occupy bits 8 through 3 of the 11 bit identifier.I spent some time on reading CAN protocol documents and discussions read many times, but I'm still struggling to understand with three points with one example. Let's imagine a CAN network with two nodes: one node sending a message to control an LED connected on the other node. For explanation purposes, You can consider your choice of microcontroller and the CAN trans receiver IC for the reference to the explanation. it may be save your time and if you want me to show the specific microcontroller and trans receiver IC. I'll refer to the PIC18F45K80 as the microcontroller and the MCP2515 as the transceiver IC.
Three points In this context:
1. Determining Receiver Node ID:
I've been searching through the MCP2515 datasheet, but I couldn't find information on how to determine the receiver node ID. How can we find or specify this ID for inclusion in the CAN message frame.
2. Data Bytes Required:
To control the LED (turning it on/off), would we need one byte or two?
I'm thinking one byte could turn it on and another could turn it off, but I'm uncertain. Could you clarify this?
3. Configuring CRC Field: Regarding error management in the CRC field, I'm unclear about the specific value needed for error monitoring. Could you provide guidance on what value should be set for effective error management in my application specific?
@Papabravo
Thanks for confirmation. So the decision of which CAN ID is assigned to which message or node within the network is made by the system designers.Node Id assignment is completely arbitrary and is not defined by the standards.
You can set that up on the receive mailbox filters. They are specific to the device that you are using.Thanks for confirmation. So the decision of which CAN ID is assigned to which message or node within the network is made by the system designers.
Imagine we've got three nodes in a CAN Network. We've given them CAN IDs: Node 1 is 0x10, Node 2 is 0x20, and Node 3 is 0x03.
Now, if we want to send a message specifically to Node 2, and we put the CAN ID 0x02 in that message, how does Node 2 know it's for him and not for the other nodes? How do the other nodes understand that this message isn't meant for them on the CAN bus?
To the OP only.I spent some time on reading CAN protocol documents and discussions read many times, but I'm still struggling to understand with three points with one example. Let's imagine a CAN network with two nodes: one node sending a message to control an LED connected on the other node. For explanation purposes, You can consider your choice of microcontroller and the CAN trans receiver IC for the reference to the explanation. it may be save your time and if you want me to show the specific microcontroller and trans receiver IC. I'll refer to the PIC18F45K80 as the microcontroller and the MCP2515 as the transceiver IC.
Three points In this context:
1. Determining Receiver Node ID:
I've been searching through the MCP2515 datasheet, but I couldn't find information on how to determine the receiver node ID. How can we find or specify this ID for inclusion in the CAN message frame.
2. Data Bytes Required:
To control the LED (turning it on/off), would we need one byte or two?
I'm thinking one byte could turn it on and another could turn it off, but I'm uncertain. Could you clarify this?
3. Configuring CRC Field: Regarding error management in the CRC field, I'm unclear about the specific value needed for error monitoring. Could you provide guidance on what value should be set for effective error management in my application specific?
@Papabravo


Since there is not enough room in the 11-bit identifier, for both the source address and the destination address it should be self-evident that the MAC Id (node address) in the message should be for the destination so that the Mask and Match filters can be used. For networks using multiple client devices the only absolute rule is that no duplicate identifiers are allowed on the network. If this was possible the arbitration scheme would fail - and we just can't abide that situation. This is not really a problem if the clients can divide up the set of servers.Thanks for confirmation. So the decision of which CAN ID is assigned to which message or node within the network is made by the system designers.
Imagine we've got three nodes in a CAN Network. We've given them CAN IDs: Node 1 is 0x10, Node 2 is 0x20, and Node 3 is 0x03.
Now, if we want to send a message specifically to Node 2, and we put the CAN ID 0x02 in that message, how does Node 2 know it's for him and not for the other nodes? How do the other nodes understand that this message isn't meant for them on the CAN bus?

