  We aim to directly determine the kinetic temperature and spatial density with
formaldehyde for the $\sim$100 brightest ATLASGAL-selected clumps at 870 $\mu$m
representing various evolutionary stages of high-mass star formation. Ten
transitions ($J$ = 3-2 and 4-3) of ortho- and para-H$_2$CO near 211, 218, 225,
and 291 GHz were observed with the APEX 12 m telescope. Using non-LTE models
with RADEX, we derive the gas kinetic temperature and spatial density using the
measured p-H$_2$CO 3$_{21}$-2$_{20}$/3$_{03}$-2$_{02}$,
4$_{22}$-3$_{21}$/4$_{04}$-3$_{03}$, and 4$_{04}$-3$_{03}$/3$_{03}$-2$_{02}$
ratios. The gas kinetic temperatures derived from the p-H$_2$CO
3$_{21}$-2$_{20}$/3$_{03}$-2$_{02}$ and 4$_{22}$-3$_{21}$/4$_{04}$-3$_{03}$
line ratios are high, ranging from 43 to $>$300 K with an unweighted average of
91 $\pm$ 4 K. Deduced $T_{\rm kin}$ values from the $J$ = 3-2 and 4-3
transitions are similar. Spatial densities of the gas derived from the
p-H$_2$CO 4$_{04}$-3$_{03}$/3$_{03}$-2$_{02}$ line ratios yield 0.6-8.3
$\times$ 10$^6$ cm$^{-3}$ with an unweighted average of 1.5 ($\pm$0.1) $\times$
10$^6$ cm$^{-3}$. A comparison of kinetic temperatures derived from p-H$_2$CO,
NH$_3$, and the dust emission indicates that p-H$_2$CO traces a distinctly
higher temperature than the NH$_3$ (2,2)/(1,1) transitions and the dust,
tracing heated gas more directly associated with the star formation process.
The H$_2$CO linewidths are found to be correlated with bolometric luminosity
and increase with the evolutionary stage of the clumps, which suggests that
higher luminosities tend to be associated with a more turbulent molecular
medium. It seems that the spatial densities measured with H$_2$CO do not vary
significantly with the evolutionary stage of the clumps. However, averaged gas
kinetic temperatures derived from H$_2$CO increase with time through the
evolution of the clumps.
