Lab 6: The Internet of Things and Serial Peripheral Interface
Introduction
This lab introduces SPI communication and the Internet of Things. The DS1722 temperature sensor records the ambient temperature and sends the data to the STM32L432KCU MCU. Temperature data is transferred via USART to a local website hosted by the ESP8266. Temperature resolution and LED control options are presented on the website to modify MCU and temperature sensor behavior.
Design and Testing
Website features for controlling an external LED, the temperature resolution, and temperature display were implemented with HTML code and transferred to the webiste with USART. Temperature resolution can be configured between 8 and 12 bits. Resolution selections write to the configuration register in the DS1722. Temperature data is continuously read as two separate character values, with the signed most significant character being sent first followed by the least significant character repesenting the decimal portion. The least significant character is corrected by a factor of 256 to get it to its intended fractional value. To combat the high-frequency noise interfering MISO communication, a low-pass filter was constrcuted with the 10 pF capcitor and a 1.6 kOhm resistor. These values were selected such that the corner frequency (10 MHz) is 5 times that of the baud rate (2 MHz).
Calculations
The website control a green external LED with two buttons. When the on button is pressed, the LED activates, and turns off once the off button is pressed. The LED is powered with 5V and has a forward voltage drop of 1.88 V. Current must be limited to within 10 mA. Sufficient brightness can be achieved with a current above 5 mA, so a 560 Ohm resistor was selected based on the calculation below.

Technical Documentation
Electric Schematic
With the external LED, the primary connections were between the DS1722 sensor and the MCU. USART connections between the MCU and ESP8266 were handled internally within the E155 development board and are thus excluded. SPI pins, 5V volage, and ground connections were directly connected to the receiving pins within the temperature sensor as indicated below.

Results and Discussion
SPI communication was confirmed by reading the MISO and MOSI lines with the Logic Analyzer. The configuration write register is 0x80 which is clear in the first SPI transaction. The MSB value is later received as indicated by the reading of register 0x02 and a dummy variable is sent after to complete the transaction. Between this 16-bit transaction, the clock enable purposefully lowers and rises again to read the LSB values in the 0x01 register. The second values in each MISO transaction indicate the MSB and LSB values, which are then converted to temperature readings.

Conclusion
This lab took roughly 20 hours complete. While some obscure MISO behavior is recorded on the logic analyzer, the website successfully controls temperature readings and resolution. I learned a lot about SPI behavior, some HTML code, and USART communication, which will come in handy for the final project. There was a lot of tedious and painful debugging that stumped me, even when all individual aspects appeared to be properly implemented.
AI Prototype
ChatGPT was tested to how efficiently it can write HTML code and produce functioning SPI communication code. The first prompt it was given was:
I’m making a web portal to interface with a temperature sensor. Create a HTML page that looks good and is intuitive to show the temperature, control an LED, and change the precision of the readout.
ChatGPT handled this no problem writing hundreds of lines of code to produce a sleek website that exceeds the bare-bones implementation developed with this lab. ChatGPT certainly has no problem writing functioning HTML code.

ChatGPT was given a second prompt to test its SPI writing capabilities:
Write me a C function to carry out a SPI transaction to retrieve a temperature reading from a DS1722 sensor. Make use of CMSIS libraries for the STM32L432KC.
This code employed obscure libraries that were hard to follow and interpret. Even when including these libraries, the code would not run properly on my computer. It’s logic to send and receive data using addresses and dummy values looked promising, but it is clear that the LLM’s HTML writing capabilities is far superior than its SPI communication capabilities.
