Deadlocks aren't just cases of lock contention, they are not something that can be waited out, it is a state that can only be resolved by termination of one transaction or another.
By using transaction functions automatic retry will be performed by the driver after a transaction is terminated to resolve the deadlock.
You may also want to consider tuning your queries to try to hold fewer locks or less transactional state, since queries with larger amounts of changed state will be holding more locks, and there is more opportunity for lock contention (and deadlock) to occur between such queries.