Skip to content

hpaluch/pic32mx-tc74-temperature

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PIC32MX Temperature meter with TC74

Here is my project that uses PIC32MX with TC74 to measure temperature and print it on UART. MCC Harmony asynchronous Components (Debug, Console, I2C and other services) are utilized in this project which is new experience for me.

PIC32MX with TC74 Temp sensor

Status:

  • project finished as of Sep 24 2023
  • however "wake up" code and "Busy wait" code is untested (I never experienced that state)
  • now I will polish documentation and fix bugs.

When configured properly there should be UART output like this:

app.c:209 Starting app v1.04
app.c:253 OK: I2C ACK response from dev at ADDR=0x48. Data=0x1f
app.c:293 Data from TC74 at ADDR=0x48: CONFIG=0x40 UP READY zero mask: 0x0
app.c:386 #1 Temp=31 Celsius (raw=0x1F)
app.c:386 #2 Temp=32 Celsius (raw=0x20)
app.c:386 #3 Temp=33 Celsius (raw=0x21)
app.c:386 #4 Temp=34 Celsius (raw=0x22)
app.c:386 #5 Temp=34 Celsius (raw=0x22)

(I was holding finger on TC74 to quickly change temperature)

NOTE!

This project is hit by Hardware bug in PIC32MX Revision A1 - see PIC32MX Errata. The RA0 (LED) and RA1 GPIO pins stop working when I2C1 module is enabled (!).

Fortunately recommended workaround is working well, summarized:

diff --git a/firmware/src/config/default/peripheral/i2c/master/plib_i2c1_master.c b/firmware/src/config
/default/peripheral/i2c/master/plib_i2c1_master.c
index 89c42e7..e7f04cc 100644
--- a/firmware/src/config/default/peripheral/i2c/master/plib_i2c1_master.c
+++ b/firmware/src/config/default/peripheral/i2c/master/plib_i2c1_master.c
@@ -74,7 +74,7 @@ void I2C1_Initialize(void)
     I2C1BRG = 235;

     I2C1CONCLR = _I2C1CON_SIDL_MASK;
-    I2C1CONCLR = _I2C1CON_DISSLW_MASK;
+    I2C1CONSET = _I2C1CON_DISSLW_MASK;
     I2C1CONCLR = _I2C1CON_SMEN_MASK;

     /* Clear master interrupt flag */

See Commit bdaf154 on GitHub for details.

Program details

This project uses MCC Harmony "Core" Components in Asynchronous mode (main polling thread - "cooperative multitasking") - e.g. RTOS = No.

  • Using FRC = 8Mhz, with FRCPLL scaled to PBCLK = 48 MHz
  • MCC Harmony components:
    • Harmony Core Library with state machine
    • System Timer Service using tickless Core Timer (Core Timer is MIPS CPU feature). Tickless means that there is no fixed interrupt rate as time base, but SYS_TIME schedules one shot Timer as needed by consuming clients.
    • Console System Service - provides Console output via UART2 PLIB
    • Debug System Service - provides formatted debug messages API (like printf), requires Console
    • I2C Driver - wrapper around async. I2C PLIB
  • Peripherals CORE Timer
  • RA0_LED is blinking at 1s rate (500ms interrupt rate) using System Timer Service
  • UART2 PLIB
  • I2C1 PLIB

Required Hardware

  • Microstick II board
  • PIC32MX250F128B SPDIP - included with my Microstick board, but not guaranteed to be included with yours.
  • TC74 I2C Temperature sensor recommended "5-lead TO-220" package.
  • USB Console Cable #954 - or any other usable USB to UART adapter. WARNING! To ensure 3.3V compatibility with PIC, connect only Input (White) and Ground (Black). Keep Output (Green) not connected to avoid 5V on 3.3V pin (this USB Version of PIC32MX have pins 21,22 NOT 5V tolerant!)
  • 2 pull-up resistors around 2k2 kOhm for SCA and SDL signals on I2C. Connected to VDD (3.3V test point on board).

Microstick II Configurtion:

  • closed LED Jumper J3 (so LED is connected to PIN2 RA0
  • programming switch S1 in A position (where PINS 4 & 5 used for programming and debugging)

Required Wiring of Microstick II:

Microstick II Pin Signal Target Detail
17 SCL1 2K pull-up I2C1 clock
18 SDA1 2K pull-up I2C1 data
21 U2TX Console #954, White UART2 TX (PIC Output, PC Input)
22 U2RX NC UART2 RX (PIC Input, PC Output) - not connected
27 GND Console #954, Black -

Required wiring for TC74 in 5-lead TO-220:

TC74 pin Signal Microstick II pin
2 SDA I2C data
3 GND Ground
4 SCLK I2C Clock
5 VDD +3.3V

Software requirements

WARNING! Before opening this project you should inspect Manifest file firmware/src/config/default/harmony-manifest-success.yml and ensure that your Harmony repository contains specified components and exactly same versions.

  • currently the only reliable way is to do this (I'm not kidding!):
  • create Empty MCC Harmony project and ensure that you specified proper CPU PIC32MX250F128B SPDIP
  • when Wizard finishes it will automatically invoke MCC Content Manager
  • you have to select MCC Harmony (the only available choice)
  • next you have to select exactly same components and versions as listed in Manifest firmware/src/config/default/harmony-manifest-success.yml
  • once MCC finished Downloading and starts you can:
  • Close MCC
  • Close that empty project
  • Open this project - MCC should work without any complaint

Before running this program you need to define proper I2C address of your TC74 sensor in app.c. You have to read your package name:

  • in my case it is TC74A0
  • where A0 means that I2C address is 0x48
  • it is also default address in firmware/src/app.c:
#define APP_TC74_SLAVE_ADDR_A0 0x48
#define APP_TC74_SLAVE_ADDR_A5 0x4D
#define APP_TC74_SLAVE_ADDR APP_TC74_SLAVE_ADDR_A0

So if your TC74 has suffix different from A0 you need to look into TC74 datasheet and #define proper I2C address. Otherwise there will be error message on UART like this:

app.c:209 Starting app v1.03
ERROR: app.c:258 I2C Read from ADDR=0x48 failed. Is TC74 connected? i2cEvent=-1
ERROR: app.c:407 SYSTEM HALTED due error. appState=9999

Software requirements

Resources

This code is based on several Internet resources including:

PIC32MX is MIPS32 M4K based CPU Core with peripherals from Microchip. Please see links below for more information:

About

Measuring temperature using TC74 I2C sensor and PIC32MX on Microstick II board utilizing MCC Harmony tool.

Resources

License

Stars

Watchers

Forks

Packages

No packages published