Experiments were conducted in a compression–expansion test engine to investigate the combustion characteristics in a homogeneous charge compression ignition (HCCI) engine fuelled with dimethyl ether. Two types of analyses were performed. In the first, ultraviolet–visible (UV–Vis) light absorbance was investigated to identify the formation behaviour of HCHO and OH during HCCI combustion. In the second, knocking combustion was investigated by analysing the spatially integrated flame luminosity and in-cylinder pressure oscillations. The time-resolved HCHO and OH profiles at different equivalence ratios showed that HCHO absorbance increased in the low-temperature reaction (LTR) and thermal-preparation regions and gradually decreased as the combustion approached the high-temperature reaction (HTR) region. The in-cylinder temperature in the LTR region had little effect on the rate of the maximum pressure rise, and this did not change much at different equivalence ratios. The results demonstrated that there was a marked difference between the intensity of the flame emissions of non-knocking and knocking events. The time-resolved integrated absorbance spectra of HCHO with peaks at 328, 340, and 354 nm that occurred before the OH peaks appeared suggested that when a certain threshold ratio of (dP/dθLTR)/(dP/dθHTR) was reached, the amount of HCHO decreased due to reactions in the thermal-preparation region while the tendency to knock increased.