Skip to content

Commit 27413b1

Browse files
committed
MPAE-19448 created working project, updated readme and main-meta
1 parent ce6ebc5 commit 27413b1

19 files changed

+188
-323
lines changed

.main-meta/main.json

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"content": {
55
"metaDataVersion": "1.3.0",
66
"name": "com.microchip.mcu8.mplabx.project.pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors",
7-
"version": " ",
8-
"displayName": "",
7+
"version": "1.0.0",
8+
"displayName": "pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors",
99
"projectName": "pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors",
1010
"shortDescription": "Reads proximity sensor value. With printf error handling, sends values to MPLAB Data Visualizer every 250 ms. Uses Timer driver callbacks for sampling frequency.",
1111
"ide": {
@@ -19,12 +19,12 @@
1919
}
2020
],
2121
"dfp": {
22-
"name": "",
23-
"semverRange": ""
22+
"name": "PIC18F-Q_DFP",
23+
"semverRange": "^3.0.0"
2424
},
2525
"configurator": {
26-
"name": "",
27-
"semverRange": ""
26+
"name": "MCC",
27+
"semverRange": "^5.6.2"
2828
},
2929
"device": {
3030
"metaDataVersion": "1.0.0",
@@ -37,8 +37,23 @@
3737
}
3838
},
3939
"author": "Glen Nilsen",
40-
"peripherals": [],
41-
"keywords": [],
40+
"peripherals": [
41+
"I2C",
42+
"GPIO",
43+
"UART"
44+
],
45+
"keywords": [
46+
"Data Visualizer",
47+
"MPLAB Data Visualizer",
48+
"I2C",
49+
"UART",
50+
"Getting Started",
51+
"Melody",
52+
"MCC Melody",
53+
"Curiosity Nano Explorer",
54+
"Example Components",
55+
"MCC Melody Example Components"
56+
],
4257
"additionalData": {
4358
"longDescription": {
4459
"metaDataVersion": "1.0.0",

README.md

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,59 @@
1010

1111
# Update the title for pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors here
1212

13-
<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
13+
The [I<sup>2</sup>C Proximity Sensor Example](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=I2C.HOST.EX.RUNNING.I2C.HOST.FIND.CLIENTS&version=latest&redirect=true "I2C Proximity Sensor example"
14+
), of the [MCC Melody I<sup>2</sup>C Example Component (for the Curiosity Nano Explorer)](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=I2C.HOST.EXAMPLE.COMPONENT&version=latest&redirect=true "MCC Melody I<sup>2</sup>C Example Component for the Curiosity Nano Explorer"
15+
), is used here in the Callbacks implementation with the Printf with error handling visualization.
1416

15-
## Related Documentation
16-
17-
<!-- Any information about an application note or tech brief can be linked here. Use unbreakable links!
18-
In addition a link to the device family landing page and relevant peripheral pages as well:
19-
- [AN3381 - Brushless DC Fan Speed Control Using Temperature Input and Tachometer Feedback](https://microchip.com/00003381/)
20-
- [PIC18F-Q10 Family Product Page](https://www.microchip.com/design-centers/8-bit/pic-mcus/device-selection/pic18f-q10-product-family) -->
2117

22-
## Software Used
18+
![alt text](images/pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors_intro.png)
2319

24-
<!-- All software used in this example must be listed here. Use unbreakable links!
25-
- MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide)
26-
- MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers)
27-
- MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
28-
- MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
29-
- Microchip PIC18F-Q Series Device Support (1.4.109) or newer [(packs.download.microchip.com/)](https://packs.download.microchip.com/) -->
20+
This example reads the value of the VCNL4200 proximity sensor on the Curiosity Nano Explorer, using the Printf with error handling visualization output. Every 250 ms, an LED and a Debug I/O pin are toggled. An appropriately formatted Printf string is then sent to the [MPLAB® Data Visualizer](https://www.microchip.com/en-us/tools-resources/debug/mplab-data-visualizer "MPLAB® Data Visualizer").
3021

31-
- MPLAB® X IDE 6.25.0 or newer [(MPLAB® X IDE 6.25)](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide)
32-
- MPLAB® XC8 3.0.0 or newer compiler [(MPLAB® XC8 3.0)](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8)
22+
## Operation
23+
The below image of the MPLAB Data Visualizer shows the application running, where proximityValue is displayed in a Printf string. Any I<sup>2</sup>C errors would also be displayed.
3324

34-
## Hardware Used
25+
When running the application using the MPLAB Data Visualizer, you should see something similar to the following:
3526

36-
<!-- All hardware used in this example must be listed here. Use unbreakable links!
37-
- PIC18F47Q10 Curiosity Nano [(DM182029)](https://www.microchip.com/Developmenttools/ProductDetails/DM182029)
38-
- Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162)
39-
- POT Click board™ [(MIKROE-3402)](https://www.mikroe.com/pot-click) -->
27+
![alt text](images/pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors.png)
4028

4129
## Setup
4230

43-
<!-- Explain how to connect hardware and set up software. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
31+
The following outlines the complete MPLAB Code Configuration (MCC) Melody configuration, including all the selected tasks implemented in this example.
32+
33+
![alt text](images\pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors_configuration.png)
34+
35+
![alt text](images\pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors_configuration_pins.png)
4436

45-
## Operation
4637

47-
<!-- Explain how to operate the example. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
38+
## MCC Melody Example Components
39+
Example Components are a tight integration of learning material directly into MCC. This allows users to conveniently place the configuration instructions side-by-side to the components they are configuring. For more information, refer to the [MCC Melody Example Components](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=MCC.MELODY.EXAMPLES&version=latest&redirect=true) introduction.
4840

49-
## Summary
5041

51-
<!-- Summarize what the example has shown -->
42+
## Related Documentation
43+
44+
- [MCC Melody I<sup>2</sup>C Example Component (for the Curiosity Nano Explorer)](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=I2C.HOST.EXAMPLE.COMPONENT&version=latest&redirect=true "MCC Melody I<sup>2</sup>C Example Component for the Curiosity Nano Explorer")
45+
- [MCC Melody Design Patterns for Control Flow](https://onlinedocs.microchip.com/g/GUID-7CE1AEE9-2487-4E7B-B26B-93A577BA154E "MCC Melody Design Patterns for Control Flow")
46+
47+
- [Curiosity Nano Explorer User Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/CNANO-Explorer-UserGuide-DS50003716.pdf "Curiosity Nano Explorer Users Guide")
48+
49+
- [PIC18F57Q43 Data Sheet](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/DataSheets/PIC18F27-47-57Q43-Data-Sheet-40002147F.pdf "PIC18F57Q43 Data Sheet")
50+
51+
## Software Used
52+
- [MPLAB® X IDE](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide) v6.25 or newer
53+
- [MPLAB® XC8](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8) v3.00 or newer
54+
55+
- [MPLAB® Code Configurator](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator) (MCC) Plug-in v5.6.2 or newer (*Tools>Plugins>Installed*, search: "MCC")
56+
- [MPLAB® Data Visualizer](https://www.microchip.com/en-us/tools-resources/debug/mplab-data-visualizer) Plug-in v1.4.1926 or newer (*Tools>Plugins>Installed*, search: "Data Visualizer")
57+
- MCC Melody I2C_Host Example Component for the Curiosity Nano Explorer v1.0.0 or newer
58+
- MCC Core v5.8.2 or newer
59+
- Single Page Application (SPA) Host v1.0.0 or newer
60+
- MCC Melody Core v2.9.1 or newer
61+
62+
Open the MCC Content Manager ![CM_icon](images/Icon-MPLAB-CM24.png) to verify the MCC Core and MCC Melody Core versions.
63+
64+
![alt text](images/MCC_Core_ContentLibrary_Versions_SPA.png)
65+
66+
## Hardware Used
67+
- PIC18F57Q43 Curiosity Nano [(DM164150)](https://www.microchip.com/en-us/development-tool/DM164150)
68+
- Curiosity Nano Explorer [(EV58G97A)](https://www.microchip.com/en-us/development-tool/EV58G97A)

images/Icon-MPLAB-CM24.png

1.46 KB
Loading
64.6 KB
Loading
74.9 KB
Loading
220 KB
Loading
73.3 KB
Loading
18.7 KB
Loading

pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors.X/main.c

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,37 @@
2525
*
2626
* @ingroup i2c_host example
2727
*
28-
* @version I2C_HOST EXAMPLE Example Version 1.0.0
28+
* @version I2C_HOST EXAMPLE Example Version 1.0.1
2929
*
3030
* @brief Generated file for
3131
* Example: 4. I2C Proximity Sensor
3232
* Implementation: Interrupts with callbacks
3333
* Visualization: Printf with error handling
34-
* MCU Device family: PIC18F/18F
34+
* MCU Device family: PIC18
3535
*/
36+
3637
#include "mcc_generated_files/system/system.h"
3738

38-
// TODO: Replace TimerX with name of const struct TIMER_INTERFACE, from MCC Generated Files > timer > {timer_header}X
39-
static const struct TIMER_INTERFACE *Timer = &Timer2; // TODO: Replace TimerX with the timer instance number
40-
41-
uint8_t VCNL4200_Initialize(void);
42-
uint8_t VCNL4200_ProximityRead(uint16_t* proximityValue);
43-
void Timer_Callback_250ms(void);
44-
const uint8_t* I2CErrorToString(uint8_t error);
4539

4640
// Note: VCNL4200 - High Sensitivity Long Distance Proximity and Ambient Light Sensor With I2C Interface
4741
// Reference to the VCNL4200 data sheet: https://www.vishay.com/docs/84430/vcnl4200.pdf
4842
// The VCNL4200 command codes are located in Table 1 (page 9) of the VCNL4200 data sheet
4943
#define PROXIMITY_I2C_ADDRESS ((uint8_t)0x51)
5044
#define PROXIMITY_REGISTER ((uint8_t)0x08)
5145

52-
uint16_t proximityValue; // VCNL4200 sensor result
53-
uint8_t errorState = I2C_ERROR_NONE;
54-
volatile bool timerTick = 0; // volatile because this variable is used inside & outside the ISR.
46+
uint8_t VCNL4200_Initialize(void);
47+
uint8_t VCNL4200_ProximityRead(uint16_t* proximityValue);
48+
void Timer_Callback_250ms(void);
49+
const uint8_t* I2CErrorToString(uint8_t error);
50+
51+
// TODO: Replace TimerX with number of Timer chosen as dependency.
52+
// Matches name of const struct TIMER_INTERFACE, from MCC Generated Files > timer > tmrx.c
53+
static const struct TIMER_INTERFACE *Timer = &Timer2;
54+
55+
static volatile bool timerTick = false; // volatile because this variable is used inside & outside the ISR.
56+
static uint16_t proximityValue; // VCNL4200 sensor result
57+
static volatile uint8_t frameCount;
58+
static i2c_host_error_t errorState = I2C_ERROR_NONE;
5559

5660
uint8_t VCNL4200_ProximityRead(uint16_t* proximityValue)
5761
{
@@ -79,19 +83,26 @@ uint8_t VCNL4200_ProximityRead(uint16_t* proximityValue)
7983

8084
const uint8_t* I2CErrorToString(uint8_t error)
8185
{
86+
const uint8_t* errorString;
8287
switch (error)
8388
{
8489
case I2C_ERROR_NONE:
85-
return "I2C_ERROR_NONE";
90+
errorString = "I2C_ERROR_NONE";
91+
break;
8692
case I2C_ERROR_ADDR_NACK:
87-
return "I2C_ERROR_ADDR_NACK";
93+
errorString = "I2C_ERROR_ADDR_NACK";
94+
break;
8895
case I2C_ERROR_DATA_NACK:
89-
return "I2C_ERROR_DATA_NACK";
96+
errorString = "I2C_ERROR_DATA_NACK";
97+
break;
9098
case I2C_ERROR_BUS_COLLISION:
91-
return "I2C_ERROR_BUS_COLLISION";
99+
errorString = "I2C_ERROR_BUS_COLLISION";
100+
break;
92101
default:
93-
return "UNKNOWN_ERROR";
102+
errorString = "UNKNOWN_ERROR";
103+
break;
94104
}
105+
return errorString;
95106
}
96107

97108
uint8_t VCNL4200_Initialize(void)
@@ -115,36 +126,34 @@ uint8_t VCNL4200_Initialize(void)
115126

116127
void Timer_Callback_250ms(void)
117128
{
118-
timerTick = 1;
129+
timerTick = true;
119130
}
120131

121132
int main(void)
122133
{
123134
__delay_ms(500); // Prevent program running when programming
124-
125135
SYSTEM_Initialize();
126136
INTERRUPT_GlobalInterruptEnable();
127-
printf("Example: 4. I2C Proximity Sensor, Implementation: Interrupts with callbacks, Visualization: Printf with error handling \r\n");
128-
printf("MCU Device family: PIC18F/18F \r\n\r\n");
137+
(int) printf("Example: 4. I2C Proximity Sensor, Implementation: Interrupts with callbacks, Visualization: Printf with error handling \r\n");
138+
(int) printf("MCU Device family: PIC18 \r\n\r\n");
129139

130140
errorState = VCNL4200_Initialize(); // Initializes the proximity sensor (VCNL4200) over the I2C bus
131-
printf("I2C proximity sensor initialize status: %d - %s \r\n\r\n", errorState, I2CErrorToString(errorState));
141+
(int) printf("I2C proximity sensor initialize status: %d - %s \r\n\r\n", errorState, I2CErrorToString(errorState));
132142
Timer->TimeoutCallbackRegister(Timer_Callback_250ms);
133-
INTERRUPT_GlobalInterruptEnable();
134143

135144
while(1)
136145
{
137-
if(timerTick == 1)
146+
if(timerTick == true)
138147
{
139148
errorState = VCNL4200_ProximityRead(&proximityValue);
140149
if (errorState != I2C_ERROR_NONE)
141150
{
142-
printf("The proximity sensor error is: %d - %s\r\n", errorState, I2CErrorToString(errorState));
151+
(int) printf("The proximity sensor error is: %d - %s\r\n", errorState, I2CErrorToString(errorState));
143152
}
144-
printf("The proximityValue is: %d\r\n", proximityValue);
153+
(int) printf("The proximityValue is: %d\r\n", proximityValue);
145154
IO_LED_Toggle();
146155
IO_Debug_Toggle();
147-
timerTick = 0;
156+
timerTick = false;
148157
}
149158
}
150159
}

pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors.X/mcc-manifest-autosave.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
manifest_file_version: 1.0.0
44
project: pic18f57q43-i2c-proximity-sensor-callbacks-printf-errors
5-
creation_date: 2025-04-03T14:51:17.525+02:00[Europe/Berlin]
5+
creation_date: 2025-10-23T14:20:26.520+02:00[Europe/Berlin]
66
operating_system: Windows 11
77
mcc_mode: IDE
88
mcc_mode_version: v6.25
99
device_name: PIC18F57Q43
1010
compiler: XC8 3.00
11-
mcc_version: 5.5.2
12-
mcc_core_version: 5.7.1
13-
content_manager_version: 5.0.1
11+
mcc_version: 5.6.2
12+
mcc_core_version: 5.8.2
13+
content_manager_version: 6.0.3-rc.b
1414
is_mcc_offline: false
15-
is_using_prerelease_versions: true
16-
mcc_content_registries: https://registry.npmjs.org/,https://artifacts.microchip.com/artifactory/api/npm/npm/
17-
device_library: {library_class: com.microchip.mcc.melody.Library, name: Melody, version: 2.8.1}
18-
packs: {name: PIC18F-Q_DFP, version: 1.28.451}
15+
is_using_prerelease_versions: false
16+
mcc_content_registries: https://registry.npmjs.org/
17+
device_library: {library_class: com.microchip.mcc.melody.Library, name: Melody, version: 2.10.0}
18+
packs: {name: N/A, version: N/A}
1919
modules:
20-
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.0}
21-
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.1.0-dev.1}
20+
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.1}
21+
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.0.5}
2222
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
23-
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.29.1-dev.6}
23+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.29.1}
2424
- {name: '@mchp-mcc/pic18-configuration-bits-v1', type: MELODY, version: 5.3.5}
2525
- {name: '@mchp-mcc/pic18-pin-manager', type: MELODY, version: 3.7.1}
26-
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.9.1-feat.6}
26+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.11.0}
2727
- {name: '@mchp-mcc/scf-pic8-i2c-v1', type: MELODY, version: 6.1.4}
2828
- {name: '@mchp-mcc/scf-pic8-interrupt-v1', type: MELODY, version: 5.2.11}
2929
- {name: '@mchp-mcc/scf-pic8-osc-v1', type: MELODY, version: 4.4.0}
30-
- {name: '@mchp-mcc/scf-pic8-tmr2-v1', type: MELODY, version: 5.1.1-dev.2}
31-
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.2.0}
30+
- {name: '@mchp-mcc/scf-pic8-tmr2-v1', type: MELODY, version: 5.1.1}
31+
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.2.1}
3232
- {name: '@mchp-mcc/timer', type: MELODY, version: 1.2.3}
3333
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}

0 commit comments

Comments
 (0)