1. System operating frequency setting
The register version and the library version of the STM32 system operating frequency setting are quite different. The library version of the system operating frequency is set by the SystemInit() function in system_stm32f10x.c, and other configurations are mainly in the stm32f10x_rcc.c file. For the system clock, by default, it is determined in the SetSysClock() function of the SystemInit function, and the setting is set through macro definition.
static void SetSysClock(void)
{
#ifdef SYSCLK_FREQ_HSE
SetSysClockToHSE();
#elif defined SYSCLK_FREQ_24MHz
SetSysClockTo24();
#elif defined SYSCLK_FREQ_36MHz
SetSysClockTo36();
#elif defined SYSCLK_FREQ_48MHz
SetSysClockTo48();
#elif defined SYSCLK_FREQ_56MHz
SetSysClockTo56();
#elif defined SYSCLK_FREQ_72MHz
SetSysClockTo72();
#endif
}
The higher the operating frequency, the higher the system power consumption. You do not need to update the delay_ms() function after changing the operating frequency, but you should pay special attention to the problem of setting the CAN baud rate. Changing the operating frequency will change the CAN baud rate nonlinearly.
2. CAN baud rate setting
Here, it is specially noted that the optional working frequencies in the firmware library are: 24MHz, 36MHz, 48MHz, 56MHz, 72MHz, which are set by macro definition. When set to 24MHz, 48MHz, the frequency used for calculation is 48MHz; when set to 36MHz, 72MHz, the frequency used for calculation is 72MHz; when set to 56MHz, the baud rate is calculated using 56MHz. For example, in the routine given by the battleship STM32, the working frequency is 72M and the default baud rate is 450kps (36000/[(7+8+1)*5]=450Kbps). When we change the working frequency to 36M, the baud rate is still 450kps. If the working frequency is changed to 24M, the baud rate becomes 24000/[(7+8+1)*5]=300Kbps. Why is this change, the principle is not clear yet.
The figure also gives the calculation formula of CAN baud rate. We only need to know the settings of BS1 and BS2, and the clock frequency of APB1 (usually 36Mhz, that is, the working frequency of APB1 under 72M working frequency), and we can easily calculate the baud rate. For example, if TS1=6, TS2=7 and BRP=4 are set, under the condition that the APB1 frequency is 36Mhz, the baud rate of CAN communication can be obtained = 36000/[(7+8+1)*5]=450Kbps. Set the function to CAN_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_7tq,5,CAN_Mode_Normal);//Normal mode
Optional parameters are:
#define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */
#define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */
#define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */
#define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */
#define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */
#define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
#define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
#define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
#define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
#define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
#define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
#define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */
#define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
#define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
#define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
#define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */
In actual engineering applications, the design of SJW, BS1, BS2, and BRP is involved. The meanings of the four can be found in the definition in the figure below. In the CAN initialization function:
CAN_Mode_Init(CAN_SJW_1tq,CAN_BS2_8tq,CAN_BS1_7tq,5,CAN_Mode_Normal); //Normal mode
The "5" in the STM32 firmware library function is the direct frequency division coefficient, and does not require +1, which is different from the figure below. In order to achieve reliable long-distance transmission, it is necessary to consider the reasonable combination of four parameters. The theoretically allowable transmission delay is determined by the position of the sampling point, so the selection of the sampling point position within a bit period is very important. The sampling point at the back will allow a larger transmission delay error t. , so that the system can transmit farther; on the contrary, selecting a sampling point at the front will allow a larger clock tolerance. Selecting a crystal oscillator with a small clock tolerance can make the sampling point selection position later. The CAN sampling point in STM32 is between BS1 and BS2, so setting BS1 and BS2 to a larger value can achieve maximum reliability.
Previous article:CAN communication network based on STM32---an ID configuration method
Next article:The process of porting from STM32F030C8 to GD32F130C8
Recommended ReadingLatest update time:2024-11-15 02:30
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- What are the best power solutions for agricultural drones? Vicor engineers tell you!
- EEWORLD University Hall----Automatic Control Theory Experiment Beijing Institute of Technology
- TMS320F28377 study notes - triggering ADC continuous sampling through timer
- Silicon Labs Development Kit Review – A quick test drive
- 40 days left to the college entrance examination, cheer for every young person chasing their dreams
- When the EEPROM battery runs out of power, will the stored data be lost?
- TMS320F28335 serial port flash programming
- 3-wire spi, LCD driver for HX8369
- How will Espressif ESP8266 communicate with the cloud server?
- LIS3DH three-axis accelerometer package and code