Anobium - 6 days ago

GCBASIC Library and Demo – TC77 SPI Temperature Sensor

A new GCBASIC library and demonstration program is now available for the Microchip TC77 digital SPI temperature sensor. The TC77 provides a 13‑bit temperature reading with 0.0625°C resolution and supports both SPI and MICROWIRE interfaces.

This release includes full support for both Hardware SPI and Software (bit‑banged) SPI on microcontrollers.

The demo solution outputs temperature readings to a serial terminal. Both hardware and software SPI variants have been tested on real hardware, including correct Manufacturer ID detection (0x54xx) and stable, accurate temperature readings.

Included Files

  • TC77_to_Serial_Terminal_SW_SPI_18F4550.gcb
    (Software SPI demo)
  • TC77_to_Serial_Terminal_HW_SPI_18F4550.gcb
    (Hardware SPI demo using MSSP1)
  • TC77.h
    (Full TC77 driver library)
  • 20092B.pdf
    (Microchip TC77 datasheet)

Wiring (single SI/O line)

The TC77 uses a shared SI/O pin. On the tested board:

  • CS → PortB.2
  • SCK → PortB.1
  • SI/O → PortB.0

Both TC77_DO and TC77_DI are defined as PortB.0. The library automatically releases the pin when required to avoid contention.

Hardware vs Software SPI

The demos share the same library. Only the port configuration differs:

  • Define TC77_HardwareSPI for MSSP1 hardware SPI
  • Omit the define for Software SPI bit‑bang mode
  • TC77 requires SPI Mode 0,0 (CPOL=0, CPHA=0)

On the microcontgroller tested the TC77 is wired to the SPI ports. The library includes implementation notes explaining why this works: direction toggling of TC77_DO (needed for Software SPI) must be skipped when using Hardware SPI - this is all automatic.

Library API (TC77.h)

The library provides:

  • TC77Int (whole degrees, signed magnitude)
  • TC77Dec (fractional part, 0.0625°C steps)
  • TC77Dec1 (rounded single decimal digit)
  • TC77Str (formatted “±xx.xxxx” string)
  • TC77RawRegister (raw 16‑bit register)

Key routines:

  • TC77ReadTemp
  • TC77ReadTemp12
  • TC77FormatTemp
  • TC77Shutdown / TC77Wake
  • TC77ReadManufacturerID
  • TC77Detect (full datasheet‑recommended detect sequence)

Demonstration Program

The included GCBASIC demo:

  • Configures the microcontroller
  • Initializes hardware serial at 9600 bps
  • Runs TC77Detect to confirm the sensor is genuine
  • Prints raw register values and formatted temperature strings
  • Updates once per second

The program is fully commented and suitable as a reference for integrating the TC77 into other GCBASIC projects.

Download

The library, demos, and datasheet are included in the next release.

Feedback, improvements, and additional device tests are welcome.

 
❤️
1
👍
1

Last edit: Anobium 6 days ago