Interfacing Temperature Sensor With MPLAB Xpress Evaluation Board Using I2C Communication
Interfacing Temperature Sensor With MPLAB Xpress Evaluation Board Using I2C Communication
Author: A.Siva
Reviewers:
Introduction:
MPLAB Xpress IDE cost free development platform. Its cloud Based IDE available from
microchip supporting PIC-based microcontrollers. The platform is comprised of code editor,
build automation tools, debugger, code configurator. MPLAB Xpress IDE is an end-to-end
solution enabling engineers to develop their applications from initial evaluation to final
production.
Component Requirement
Hardware:
o MPLAB Xpress Evaluation tool
o Micro-B cable
o Temperature sensor
Software
o MPLAB Xpress IDE
Note: we have onboard Temperature sensor connected with RC3,RC4
Temperature
sensor
Step 2: start creating our new project. Go to File >> New Project. Select microchip embedded
as well as standalone project then click next
Step 5: Now choose mplab xpress code configurator if its not present in your Device please
Download and install from following link. http://www.microchip.com/mplab/mplab-codeconfigurator
Step 6: Now we can see our mplab xpress configuration window and select system module in
mplab xpress configuration window .
Step 7: Make oscillator configuration and select I2C peripheral from device Resource
Step 8: Select pin RC3(I2C) ,RC4 (I2C) and select RC0 (UART) and make all selected pin as
digital.
SOURCE CODE:
#include "mcc_generated_files/mcc.h"
#define EMC1001_ADDRESS
0x38
//2transactions W + R
while(status == I2C2_MESSAGE_PENDING);
// blocking
// blocking
0x00
#define EMC_STATUS
0x01
// Status register
#define EMC_TEMP_LO
0x02
fraction
#define EMC_CONFIG
0x03
#define EMC_LIMIT
0x20
// configuration register
// THERM limit temperature (->ALARM1)
#define EMC_HIST
0x21
// THERM hysteresis
#define EMC_PROD_ID
0xFD
// Product ID
#define EMC_MANUF_ID
0xFE
// Manufacturer ID
#define EMC_REVISION
0xFF
// Revision
void main(void)
{
uint8_t data;
int8_t
temp;
uint8_t templo;
SYSTEM_Initialize();
INTERRUPT_GlobalInterruptEnable();
INTERRUPT_PeripheralInterruptEnable();
EMC1001_Write(EMC_LIMIT, 28);
EMC1001_Write(EMC_HIST,
2);
while (1) {
printf("\x0C");
puts("Temperature Sensor\n");
if (EMC1001_Read(EMC_PROD_ID, &data))
printf("Product ID: EMC1001%s\n", data ? "-1" : "");
if (EMC1001_Read(EMC_MANUF_ID, &data))
printf("Manufacturer ID: 0x%X\n", data);
if (EMC1001_Read(EMC_REVISION, &data))
printf("Revision : %d\n", data);
if (EMC1001_Read(EMC_TEMP_HI, (uint8_t*)&temp)) {
EMC1001_Read(EMC_TEMP_LO, &templo);
// get lsb
Step 10: Go to your MPLAP xpress IDE Erase all existing code and copy above code past there
and add library files then make clean and build for Export . if you done this go to download
you can see hex file for your project.
Step 11: Now, if all goes well connect the Micro B cable to pic16f18855 (mplab xpress
demonstration board) and connect it to your computer. If you done you can see your devise.
And copy that Hex file to your device. And make hardware connection.
OUTPUT
Figure 12 output
Pin connection
RC0
Prolific cable Rx
MICROCONTROLLER
SDA
SCL
PC
RX
TX
TX
RX
Temperature
sensor