Why does the main battery discharge with the alternator running? In my cessna 172S, when engine running at any RPM, the current at the main battery is below zero, indicating that the alternator is not charging the battery or the battery discharges, but the standby battery indicates a current above zero and it is charged by the alternator.

How can this happen?
Our mechanic had a similar issue with a Piper Cherokee where the battery would only charge intermittently.  It turned out there was a bad connection at the Master Switch which ran from the Alternator/voltage regulator to the Master Switch. Most of these types of electrical issues tend to be bad wiring. I would check your wiring thoroughly.