Recently, I was engaged in the can fieldbus experiment of the stm32 experimental board. I only had the serial communication of the STC51 before. In contrast, the can bus was quite complicated. At the beginning, I know that I am a newbie. I only know that the CAN bus is connected to serial communication, 485 communication, and I2C communication is used to transmit data communication. I don’t know how to work, or read the book from the basics. The basic principle.
The original CAN bus has the following features:main feature
Support CAN protocol 2.0A and 2.0B active mode
Baud rate up to 1 Mbit/s
Support time-triggered communication
send
3 send mailboxes
Priority characteristics of sent packets are software configurable
Record the timestamp of the SOF time
receive
2 receive FIFOs with 3 levels of depth
14-bit wide variable filter group - shared by the entire CAN
List of identifiers
FIFO overflow processing can be configured
Record the timestamp of receiving SOF time
Support time-triggered communication mode
Disable automatic retransmission mode
16-bit free running timer
Timer resolution configurable
Timestamp can be sent in the last 2 data bytes
management
Interrupt can be masked
The mailbox occupies a single address space, which is convenient for improving software efficiency.
After reading these features, the questions appear one by one,
1. What is the time trigger function?
2. What is the sending email?
3. What is the message?
4. What is a timestamp?
5. What is the receive FIFO?
6. What is a filter?
Ok, look down with questions, after reading it,
Message:
The message contains the complete data information to be sent
Send email:
There are 3 sending mailboxes for software to send messages. The sending scheduler determines which mailbox message is sent first according to the priority.
Receive filter:
There are a total of 14 variable-width/configurable identifier filter groups. The software programs them to select the packets they need in the packets received by the pins and discard the other packets.
Receive FIFO
There are 2 receive FIFOs, and each FIFO can store 3 complete messages. They are completely managed by hardware
Operating mode
bxCAN has three main modes of operation: initialization, normal and sleep modes.
Initialization mode
* The software requests bxCAN to enter the initialization mode by setting the INRQ bit of the CAN_MCR register, and then waits for the hardware to confirm the INAK bit of the CAN_MSR register.
* The software requests bxCAN to exit the initialization mode by clearing the INRQ bit of the CAN_MCR register to 0. When the hardware clears the INAK bit of the CAN_MSR register, the initialization mode exit is confirmed.
* When bxCAN is in the initialization mode, the reception and transmission of the message are disabled, and the CANTX pin outputs the recessive bit (high level).
Normal mode
After the initialization is complete, the software should put the hardware into normal mode in order to receive and send messages normally. The software can request to enter the normal mode from the initialization mode by clearing the INRQ bit of the CAN_MCR register, and then wait for the hardware to acknowledge the INAK bit of the CAN_MSR register. In synchronization with the CAN bus, that is, after monitoring 11 consecutive recessive bits (equivalent to bus idle) on the CANRX pin, bxCAN can receive and transmit packets normally.
The setting of the initial value of the filter does not need to be done in the initialization mode, but it must be done in the inactive state (the corresponding FACT bit is 0). The filter's bit width and mode settings must be completed in the initialization mode before entering normal mode.
Sleep mode (low power consumption)
Medical Equipment Battery,Cr123 Batteries,Lithium Battery 123,Cr2 Lithium Battery
Jiangmen Hongli Energy Co.ltd , https://www.honglienergy.com