The code is developed for the hardware NUCLEO-L432KC or any other board with SPI communication and the Digilent Pmod ALS1 ambient light sensor module. The purpose is to make students to understand the development process. They need to study the original analog to digital converter documentation to understand how the converter 16 bit output is converted to an illuminance value.
Diff: main.cpp
- Revision:
- 1:d1f1c7d9fbba
- Parent:
- 0:f8565ce9a7ca
--- a/main.cpp Tue Sep 14 11:33:44 2021 +0000 +++ b/main.cpp Sun Jan 09 19:55:59 2022 +0000 @@ -58,9 +58,10 @@ // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 12MHz clock rate spi.format(8,0); - spi.frequency(12000000); + spi.frequency(2000000); // 1 to 4 MHz recommend for the adc081s021 // ready to wait the conversion start alsCS.write(1); + ThisThread::sleep_for(1ms); while (true) { if(sw2.read() == 0){ @@ -95,11 +96,13 @@ // Begin the conversion process and serial data output alsCS.write(0); + ThisThread::sleep_for(1ms); // Reading two 8bit bytes by writing two dymmy 8bit bytes alsByte0 = spi.write(0x00); alsByte1 = spi.write(0x00); // End of serial data output and back to tracking mode alsCS.write(1); + ThisThread::sleep_for(1ms); // Check the http://www.ti.com/lit/ds/symlink/adc081s021.pdf // The data looks like 0000AAAA AAAA0000 on the alsByte0 alsByte1 printf("alsByte0 alsByte1 in hexadecimal %X %X\r\n",alsByte0, alsByte1);