Cause
When porting PS2 code for the project, I thought it was a simple thing. I closed it for several hours. The data I read has been incorrect (the data beat is unstable). I decided to give up, but I still decided to step on the pit to the end! So there is this article
Solution direction
Based on the previous experience of pit drainage, the problems may lie in the following places
-
- hardware problem IO port configuration, clock tree configuration and timer configuration. The underlying driver code is not suitable (the widely circulated code is F103 version)
Problem exploration
-
-
- hardware problem
-
-
-
- an F103 board was found and driven normally. The problem of PS2 damage and wire open circuit was eliminated. IO port configuration
-
-
-
- the IO port configured according to the official routine, tested that the output of each IO port is normal, and tried to modify the speed of the IO port, which is useless. The underlying driver code is not adapted to the
-
-
-
- PS2 driver code. Only the following lines refer to the underlying
-
#define DI HAL_GPIO_ReadPin(PS2_DAT_GPIO_Port,PS2_DAT_Pin)
#define DO_H HAL_GPIO_WritePin(PS2_CMD_GPIO_Port,PS2_CMD_Pin,GPIO_PIN_SET)
#define DO_L HAL_GPIO_WritePin(PS2_CMD_GPIO_Port,PS2_CMD_Pin,GPIO_PIN_RESET)
#define CS_H HAL_GPIO_WritePin(PS2_CS_GPIO_Port,PS2_CS_Pin,GPIO_PIN_SET)
#define CS_L HAL_GPIO_WritePin(PS2_CS_GPIO_Port,PS2_CS_Pin,GPIO_PIN_RESET)
#define CLK_H HAL_GPIO_WritePin(PS2_CLK_GPIO_Port,PS2_CLK_Pin,GPIO_PIN_SET)
#define CLK_L HAL_GPIO_WritePin(PS2_CLK_GPIO_Port,PS2_CLK_Pin,GPIO_PIN_RESET)
Check the macro definition of each IO port to correspond to the IO port on the board. Delay is also used in many places in the source code_ms/delay_US function uses a mature timer library to ensure the accuracy of delay, so this problem is also eliminated
4. Timer configuration
unlike F1, which uses TIM4 as the internal clock, F4 uses tim5, but both are ordinary timers and have no essential difference, so the problem is obviously not here
5. Clock tree configuration
finally, the problem is located here
referring to the official routine, change the master clock frequency from 180mhz to 72mhz. It is normal
in other words, PS2 has high requirements for communication timing. The maximum clock frequency of F4 will accelerate the communication frequency, which may lead to the collapse of some protocols, so the data is unstable.
Prospect
Of course, the optimal solution is not to change the clock frequency of the chip, which will affect the execution rate of other programs. Theoretically, the timing can be restored to normal by adding a certain delay operation to the driver code, but I didn’t do it because of time. I hope interested players can have an in-depth study, and it’s best to share the code. (not found on the Internet at present)
Read More:
- How to Solve STM32 no flash error
- [Solved] Keil5 burn STM32F chip Error: error: Flash download failed – “cortex-m4″“
- [Solved] STM32F4 MDK5 Software Simulate Error: error 65: no ‘read‘ permission
- [Solved] STM8L151 IAR Project Compile Error: Fatal Error[Pe035]: #error directive: “Please select first the target STM8L…
- How to Solve Hyperf Failed to Start Error After Aliyun ACM Installed
- How to Solve J-link Error (Two Command Errors & Solution)
- How to Solve Logstash error: failed to execute action
- How to Solve Pycharm SQL Union Error
- How to Solve Hmaster hangs up issue due to namenode switching in Ha mode
- How to Solve DVA switches history to browserhistory Error
- How to Solve Error: Heartbeating to master:7182 failed.
- How to Solve Android Arouter Frame Autowired Error
- How to Solve elasticSearch8.1.2 Install Error in Win10
- How to Solve Error: Type mismatch: cannot convert from Object to Car
- How to Solve Loadrunner Error: Failed to find .cfg file
- How to Solve Error: could not read ok from ADB Server.failed to start daemon error: cannot connect to daemon
- How to Solve Error: failed to load response
- How to Solve Docker failed to initialize Error
- How to Solve PageHelper.startPage count Error
- [Solved] STM32 Use DAP to Download Error: Error: Flash Download failed – “Cortex-M3“