Configuring audio gateway with Asterisk

Hi all
After solving my register problem with my SIP provider, now i have some other issues with configuring an audio gateway with my Asterisk.
First let me tell, that calls between extensions work correctly. Also, i have a different SIP provider which provides a trunk, that also works correctly. When i make an outgoing call, it connects fast and call quality is OK, same if i receive an incoming call.
The problem is with the other provider, who happens to provide our main office number.
They don’t provide a SIP trunk, but analog phone lines (and internet)
So, we are connected by optic cable. This enters a GPON, which provides two analog phone lines, internet and cable TV services.
The rest of our analog phone lines comes from an audio gateway. It is an AudioCodes MP114 with 4 FXO ports. This is the provider’s equipment.
We installed a Grandstream GXW4104 audio gateway which makes the opposite: gets the 4 analog lines and provides one or more SIP trunks.
After setting up the trunk, inbound routes, outbound routes i tested the system.
Almost nothing works with the two audio gateways solution.
If i dial in and receive the call, one direction has a good call quality, but the other way the call is really bad, interrupted, etc.
If i try to dial out, it gets worse. The extension gets an error message that the call cannot be completed, gets a busy tone, and after it hangs out, the dialed phone starts to ring.
It happened that i hung up on the extension, but the destination phone kept ringing.
If i dial in, same thing happens sometimes, if i hang up, the extension keeps ringing.
I think that this issue can be related to the country settings (AC Termination Impedance, dial tones, etc)
If i’m not wrong, i set the all the US.
At this moment i don’t even know what to monitor, what to check.
What i tried is that i plugged in an analog phone in the provider’s equipment and made a test call. Call quality was perfect, so the problem is on my side.
Please advise.

Best regards,
Janos