Thanks to Ihdina for the suggestion, I will improve this code in the future.
The problem has been solved, and this i2c_wait_ack is suitable for simulating i2c (sda is push-pull output pin), that is, i2c communication with only one master and slave.
The problem lies in the i2c_wait_ack function in software-i2c because the output DR Is always 1 because the host releases the bus (the sda pin is an open-drain output). This causes a timeout, outputs a stop signal, and a NACK condition occurs.
That is, at the beginning of i2c_wait_ack, the sda pin is configured as the input pin, and when the ack signal is obtained, the sda is set as the open-drain output pin.