Skip to content

kgsinh/stm32g071_i2c_lm75

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STM32G071RB + I2C LM75 + ST7735S (SPI, interrupt-driven)

Reads temperature from an LM75-series I2C temperature sensor on an STM32G071RB and displays it both on:

  • A UART terminal, and
  • An ST7735S 1.8" TFT (SPI), driven with HAL and interrupt-based SPI transfers.

The I2C/LM75 logic is written at CMSIS (register) level, while the ST7735S display uses a HAL-based library adapted from Controllerstech and modified to use interrupts instead of polling.

Overview

  • Periodically read temperature from an LM75/LM75B-compatible sensor over I2C in polling method.
  • Convert raw reading to degrees Celsius.
  • Print to UART and render on an ST7735S TFT.
  • ST7735S SPI is non-blocking using HAL IT with completion callbacks.

Reference for the ST7735S HAL library (original, blocking):
https://controllerstech.com/st7735-1-8-tft-display-with-stm32/#info_box
Note: The original tutorial targets a different MCU and uses blocking SPI; this project runs on STM32G071RB and uses interrupt-driven SPI.

Hardware

  • MCU/Board: STM32G071RB (NUCLEO‑G071RB)
  • Sensor: LM75/LM75B (7‑bit I2C address typically 0x48–0x4F based on A2/A1/A0)
  • Display: ST7735S 1.8" TFT (SPI)
  • Power: 3.3 V for MCU, I2C sensor, and TFT
  • Debug probe: ST‑Link (on-board)

Pin Mapping (fill in with your actual CubeMX config)

I2C1 (LM75)

  • SCL: PB8
  • SDA: PB9
  • Pull-ups: 4.7 kΩ to 3.3 V on SCL & SDA (if not present on the module)

ST7735S (SPI)

  • SPIx: SPI1
  • SCK : PA5
  • MOSI: PA7
  • MISO: not used
  • CS : PB2
  • DC : PB1
  • RESET:PB0
  • BL (backlight): <GPIO, optional>

UART (logging)

  • TX: PA2
  • RX: PA3
  • Baud: 115200-8N1

LM75 Address

  • Default: 0x48 (A2/A1/A0 = GND). In HAL 8-bit form: (0x48 << 1).
  • If pins differ, compute: 0x48 | (A2<<2) | (A1<<1) | (A0<<0).

Toolchain

  • STM32CubeIDE:
  • HAL: STM32G0 HAL (bundled)
  • CMSIS: bundled with Cube
  • OS:

Build and Flash

  1. Open the repo in STM32CubeIDE (File → Open Projects from File System…)
  2. Build: Project → Build All (Debug/Release)
  3. Flash/Run: Run → Run (or Debug). Ensure ST‑Link is connected.

Notes:

  • If printing floats with printf/snprintf, enable float support:
    • Project Properties → C/C++ Build → Settings → MCU Settings → “Use float with printf/scanf”
    • Or add linker flag: -u _printf_float
  • I2C bus must have pull-ups (module or external 4.7 kΩ).

Usage

  • On power-up the firmware:
    • Initializes clocks, GPIO, I2C, UART, SPI, and the TFT.
    • Periodically reads LM75 temperature and updates both:
      • UART terminal with lines like: Temp: 25.50 C
      • TFT with the same text or a simple UI.

Example print formatting:

char temp_str[32];
snprintf(temp_str, sizeof temp_str, "Temp: %.2f C", (double)temperature_c);
// send over UART and/or draw on TFT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages