CAN Protocol Basics
CAN Frame types
- Data Frame : contains data
- Remote Frame : request data frame with specific identification
- Error Frame : report error
- Overload Frame : delays data/remote frames if process time is reloaded
Logic
Before we deal with dataframe, we need to configure binary logic.
logical 0 is always superior than logical 1. This concept is important as this is how the bus determines which data to propagate first when collision is detected.
CAN Dataframe
Classic CAN message schematic is as above. There exists classic CAN message frame and extended message frame which has extended Arbitration field.
12 bits of Arbitration Field handles data ID, specifying configuration of the data. Last bit(RTR) determines whether the message is Data(0) or Remote(1) frame.
6 bits of Control Field is related to 0000000000. First IDE bit is identifier of Extension, Basic(0) or Extended(1) frame. Next FDF bit decides whether the message is of classic CAN(0) or FD CAN(1).
Following Data, CRC, ACK fields take roles as they’re named leading to End frame filled with 1s and 3 bits of 1s stating Intermission before IDLE state.
Frame Resception
Frame recpetion process is well explained on diagram above. ANy received message without error message will be checked on ID bits with matching mask and filters. If filtering process concludes without problem the message data will be processed onits use.
Frame Transmission and Arbitration
Once IDLE state is detected nodes can freely transmit messages to the bus. In this case collision may cause data corruption. Thus Content-based Arbitration process takes place on the bus to determine which message has higher priority. Lower priority messages will lose arbitration and be rretransmitted afterwards.
Bit Time Configuration and Synchronization
Time Quantum(TQ) : fixed time unit derived from node’s system clock and baudrate prescaler
prescalers are used to configure the length of TQ. Bit time is made of multiple TQ.
$$ NTQ = NBRP * T_{clock}\\ DTQ = DBRP * T_{clock} $$
CAN controllers usually set different prescaler for nominal and data, resulting in different nominal TQ and data TQ.
Propagation Delay : the time it takes for a signal to travel from TX CAN of node1 to RX CAN of node2 and back. Maximum propagation delay is 255ns, which specifies ISO11898-1.
$$ t_{PropDelay}=2*(t_{TXD-RXD}+t_{bus}) $$
Bit Time Segement
CAN bit time is divided in 4 segments.
Sync Segment : to synchronize differnent node in network
Prop Segement : to compensate Propagation Delay. It must be longer than the maximum propagation delay.
Phase Segment : to compensate phase errors caused by differnet clocks used by different nodes.
Synchronization
CAN bus uses asynchronous serial communication. Which means each nodes use unsynchronized local clocks. Thus for every nodes to receive correct frame, synchronization is required.
- Hard Synchronization
- Performed on edges of inter frame spacing of Start of Frame. It restarts bit time of the receiving node and force the detected edge to be within the synchronization segment.
- Re Synchronization
- Shortens and lengthens bit time of the receiver node. It corrects the location of sample point in relation to detected edges except for the ones used for hard synchronization.
Error Detection and Signaling
A frame is considered valid if none of the nodes detect error until the end of message frame. Bit controller checks for 5 types of errors : Bit Error, CRC Error, Form Error, Stuff Error and ACK Error.
If error is detected by a node, it corrupts the message by intercepting with error flags which will result other nodes discarding the frame immediatly.
- Bit Error : when transmitted bit differs from monitored bit on the bus
- Exceptions → dominant bit during arbitration, dominant bit in ACK slot
- CRC Error : when received CRC doesn’t match calculated CRC
- Form Error : if fixed-form bits received incorrectly
- Stuff Error : when bit stuffing rule is violated.
- ACK Error : Transmitting node doesn’t receive ACK
Active Error Frame
If CAN controller detects any of above mentioned errors at sample point of a frame, it starts an active error flag at start of next frame.
Active error flag consists of 6 consecutive dominant bits, violating bit stuffing rule, thus destroying the whole frame.
Passive Error Frame
Passive error frame consists of 6~12 recessive bits, not dominant, to mark error.
This structure prevents one error frame stopping transmission on the entire bus for error destruction.
Fault Confinement
ensures communication even in the presence of malfunctioning nodes by distinguishing between temporary error and permanent flaws.
There can be three error-states in a node : Error Active, Error Passive, and Bus-Off.
There exists two error counters
- Transmit Error Counter(TEC) : increment by 8 on error, decrement by 1 on valid
- Receive Error Counter(REC) : increment by 1 on error, decrement by 1 on valid
Error-Active State is the normal operation mode. In case error is detected it will send active error flag.
If either TEC or REC exceeds 127, mode would change to Error-Passive mode. Error passive node is allowed to receive and transmit frames, on error, it would send passive error flag.
In Bus-Off state(TEC>255), node isn’t allowed to communicate with any other nodes.
'Communication Interface&Protocol > CAN Bus' 카테고리의 다른 글
CAN Bus (1) (0) | 2022.11.07 |
---|
댓글