The most common reason is that the CAN_TX pin has been set to logic zero before the CAN controller is initialized and enabled. Even a brief period can cause a burst of error frames.
Set the pin state to logic one before setting the CAN_TX pin to be an output. Alternatively, configure and initialize the CAN controller fully before connecting it to the CAN_TX and CAN_RX pins.
"FAQ contribution from Embedded Systems Academy, experts in CAN bus. For more information visit www.esacademy.com"