Ok there is a bit of a bug within the AA guns... for some reason when you have a conning tower with multiple gun emplacement sometimes only one will fire... The only way to cure this is to cycle through each gun emplacement using F11 and fire a single bullet.
So say you have a IX/3 conning tower. Pressing F11 takes you straight to the heavy flak... fire a shot... then press F11 go to the light gun, fire a shot and then F11 again to go to the next light gun, fire a shot... then F4 to go to the bridge view.
After doing this... your gunners should theoretically start to rake the skies with gunfire.
Or it could be what nirwana has posted. If the plane is too far out of range the gunners won't shoot, if your guns are set to fire at short range, they won't fire at a plane that looks like a speck in the sky.
Also pay attention to the ammo count. U-Boat AA gunnery is not the most reliable science... and you will go through ammo like a Cadillac goes through fuel.
Make sure the Watch Officer is set to fire at will or else... no shooting... lol Also... check that your gunners are under orders to shoot at ALL types of aircraft... If you are being attacked by bombers and your flak men are under orders to shoot only fighters... they won't shoot back. Also on the subject of orders, check what they are under orders to shoot, any target, or closing targets only.
In any case, I don't know what version of SH3 you are playing... but in any version... even in stock... when harassed by aircraft, diving is your best option... particularly with the realism type mods