I’m using the SparkFun Spectral UV Sensor - AS7331 (Qwiic) SKU: SEN-23517 and the respective Sparkfun library to measure the solar spectrum. I derived my sketch from the Basic_OneShot Example. It seems to work in general, however I wonder how I could detect when the ADC goes into saturation e.g. when UVA gets high in summer. I found a method in the library sfDevAS7331::setGain where I potentially can adjust the amplifier gain, but how can I ensure that the ADC does not exceed the full scale range producing an overflow? Is there a way to read out the raw result of an ADC output before it gets converted into uW/cm^2 ? Unfortunately, none of the examples is showing this.
Have a close look at the AS7331 data sheet. There are three bits in the status register that signal overflow during timing and conversions, and you can read that at any time.
Also, the raw ADC result will never exceed the maximum value of 0xFFFF, so seeing the maximum possible result is an indication that you need to reduce the gain.