Skip to content

Commit b7c29dc

Browse files
committed
MPAE-19438 project working, readme and main-meta updated
1 parent aed8ea3 commit b7c29dc

23 files changed

+289
-512
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-io-expander2-leds-and-buttons-polled-printf",
7-
"version": " ",
8-
"displayName": "",
7+
"version": "1.0.0",
8+
"displayName": "pic18f57q43-i2c-io-expander2-leds-and-buttons-polled-printf",
99
"projectName": "pic18f57q43-i2c-io-expander2-leds-and-buttons-polled-printf",
1010
"shortDescription": "I/O Expander 1 pins (8 LEDs) set as outputs, low (LEDs on). I/O Expander 2 pins (SW1-3, 5 joystick inputs) as digital inputs. Button/joystick turns LED off. Curiosity Nano SW resets LEDs on.",
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: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,61 @@
88
</picture>
99
</a>
1010

11-
# PIC18F57Q43 I2C_Host Example Component for CNano Explorer: I/O Expander 2 LEDs and BUTTONs (Polled, Printf)
11+
# PIC18F57Q43 I2C_Host Example Component for CNano Explorer: IO Expander 2 - LEDs and Buttons Example (Polled, Printf)
1212

13-
When running this example using the MPLAB Data Visualizer, the following is what the output will look like.
13+
The [I<sup>2</sup>C Host IO Expander 2 - LEDs and Buttons Example](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=I2C.HOST.EX.RUNNING.I2C.HOST.IOEXPANDER2.LEDS.BUTTONS&version=latest&redirect=true "I2C Host IO Expander 1 - LEDs 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 Polled implementation with the Printf visualization.
1416

15-
![alt text](images/pic18f57q43-i2c-io-expander2-leds-and-buttons-polled-printf.png)
17+
![alt text](images/pic18f57q43-i2c-io-expander2-leds-buttons-polled-printf_intro.png)
1618

17-
This is the required MCC Melody Configuration to achieve this result.
19+
On the Curiosity Nano Explorer, the pins on the I<sup>2</sup>C I/O Expander 1 are connected to active-low LEDs, while the pins on the I<sup>2</sup>C I/O Expander 2 are connected to buttons (SW1, SW2 and SW3) as well as the joystick inputs (left, right, up, down, press).
1820

19-
![alt text](images/pic18f57q43-i2c-io-expander2-leds-and-buttons-polled-printf_configuration.png)
21+
This example configures the I/O Expander 1 pins as outputs set LOW, so the active-low LEDs are initially all turned on. The I/O Expander 2 pins are configured as digital inputs. As a button press or joystick input is detected, the associated LED is turned off. The Curiosity Nano's SW is configured as a reset, turning on all the LEDs again.
2022

21-
<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
23+
## Operation
24+
When running the application using the [MPLAB® Data Visualizer](https://www.microchip.com/en-us/tools-resources/debug/mplab-data-visualizer "MPLAB® Data Visualizer"), you should see something similar to the following:
2225

23-
## Related Documentation
26+
![alt text](images/pic18f57q43-i2c-io-expander2-leds-polled-printf.png)
2427

25-
<!-- Any information about an application note or tech brief can be linked here. Use unbreakable links!
26-
In addition a link to the device family landing page and relevant peripheral pages as well:
27-
- [AN3381 - Brushless DC Fan Speed Control Using Temperature Input and Tachometer Feedback](https://microchip.com/00003381/)
28-
- [PIC18F-Q10 Family Product Page](https://www.microchip.com/design-centers/8-bit/pic-mcus/device-selection/pic18f-q10-product-family) -->
28+
**Note:** Behaviour is not as reliable as in the Callbacks version.
2929

30-
## Software Used
30+
**Note:** Debug I/O is not actively used. However, since the SW pin on the Curiosity Nano is a Debug I/O pin, so when pushing the IO_Reset, a toggle is picked up on the Debug I/O pin.
3131

32-
<!-- All software used in this example must be listed here. Use unbreakable links!
33-
- MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide)
34-
- MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers)
35-
- MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
36-
- 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)
37-
- Microchip PIC18F-Q Series Device Support (1.4.109) or newer [(packs.download.microchip.com/)](https://packs.download.microchip.com/) -->
32+
## Setup
33+
The image below outlines the complete MPLAB Code Configurator (MCC) Melody configuration, including all the selected tasks implemented in this example, as seen in the MCC Melody Builder.
34+
![alt text](images/pic18f57q43-i2c-io-expander2-leds-buttons-polled-printf_configuration.png)
3835

39-
- 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)
40-
- 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)
36+
![alt text](images/pic18f57q43-i2c-io-expander2-leds-buttons-polled-printf_pins_configuration.png)
4137

42-
## Hardware 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.
4340

44-
<!-- All hardware used in this example must be listed here. Use unbreakable links!
45-
- PIC18F47Q10 Curiosity Nano [(DM182029)](https://www.microchip.com/Developmenttools/ProductDetails/DM182029)
46-
- Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162)
47-
- POT Click board™ [(MIKROE-3402)](https://www.mikroe.com/pot-click) -->
4841

49-
## Setup
42+
## Related Documentation
5043

51-
<!-- 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 -->
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")
5246

53-
## Operation
47+
- [Curiosity Nano Explorer User Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/PIC18F57Q43-Curiosity-Nano-HW-UserGuide-DS40002186B.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
5461

55-
<!-- Explain how to operate the example. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
62+
Open the MCC Content Manager ![CM_icon](images/Icon-MPLAB-CM24.png) to verify the MCC Core and MCC Melody Core versions.
5663

57-
## Summary
64+
![alt text](images/MCC_Core_ContentLibrary_Versions_SPA.png)
5865

59-
<!-- Summarize what the example has shown -->
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
185 KB
Loading
18.7 KB
Loading
77.2 KB
Loading
53.1 KB
Loading

pic18f57q43-i2c-io-expander2-leds-buttons-polled-printf.X/main.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
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: 3. I2C IO Expander 2 - LEDs and Buttons
3232
* Implementation: Polled
3333
* Visualization: Printf
34-
* MCU Device family: PIC18F/18F
34+
* MCU Device family: PIC18
3535
*/
3636

3737
#include "mcc_generated_files/system/system.h"
@@ -58,16 +58,16 @@
5858
#define MCP23008_OLAT 0x0A
5959

6060
extern void DELAY_milliseconds(uint16_t milliseconds);
61-
uint8_t MCP23008_Read(uint8_t i2c_address, uint8_t reg, uint8_t* data);
62-
uint8_t MCP23008_Write(uint8_t i2c_address, uint8_t reg, uint8_t data);
63-
void printButtonPressed(int pressedButton);
64-
void button_led_control(void);
61+
static uint8_t MCP23008_Read(uint8_t i2c_address, uint8_t reg, uint8_t* data);
62+
static uint8_t MCP23008_Write(uint8_t i2c_address, uint8_t reg, uint8_t data);
63+
static void printButtonPressed(int pressedButton);
64+
static void button_led_control(void);
6565

6666
static volatile bool resetFlag = false;
6767
// All joystick pins re-mapped as they are not connected to Curiosity Nano GPIO by default
6868
static const char* buttonLabels[8] = {"J-UP", "J-LEFT", "J-DOWN", "J-RIGHT", "J-PUSH", "SW3", "SW2", "SW1"};
6969

70-
uint8_t MCP23008_Read(uint8_t i2c_address, uint8_t reg, uint8_t* data)
70+
static uint8_t MCP23008_Read(uint8_t i2c_address, uint8_t reg, uint8_t* data)
7171
{
7272
i2c_host_error_t errorState = I2C_ERROR_NONE;
7373
size_t txLength = 1;
@@ -79,6 +79,10 @@ uint8_t MCP23008_Read(uint8_t i2c_address, uint8_t reg, uint8_t* data)
7979
uint8_t waitCounter = 100;
8080
if(I2C_Host.WriteRead((uint16_t)(i2c_address), txBuffer, txLength, data, rxLength))
8181
{
82+
while(!I2C_Host.IsBusy())
83+
{
84+
//Wait here until I2C bus can start transmitting
85+
}
8286
while (I2C_Host.IsBusy() && (waitCounter > 0U))
8387
{
8488
I2C_Host.Tasks();
@@ -91,7 +95,7 @@ uint8_t MCP23008_Read(uint8_t i2c_address, uint8_t reg, uint8_t* data)
9195
}
9296

9397

94-
uint8_t MCP23008_Write(uint8_t i2c_address, uint8_t reg, uint8_t data)
98+
static uint8_t MCP23008_Write(uint8_t i2c_address, uint8_t reg, uint8_t data)
9599
{
96100
i2c_host_error_t errorState = I2C_ERROR_NONE;
97101
size_t txLength = 2;
@@ -103,6 +107,10 @@ uint8_t MCP23008_Write(uint8_t i2c_address, uint8_t reg, uint8_t data)
103107
uint8_t waitCounter = 100;
104108
if(I2C_Host.Write((uint16_t)i2c_address, txBuffer, txLength))
105109
{
110+
while(!I2C_Host.IsBusy())
111+
{
112+
//Wait here until I2C bus can start transmitting
113+
}
106114
while (I2C_Host.IsBusy() && (waitCounter > 0U))
107115
{
108116
I2C_Host.Tasks();
@@ -114,15 +122,15 @@ uint8_t MCP23008_Write(uint8_t i2c_address, uint8_t reg, uint8_t data)
114122
return errorState;
115123
}
116124

117-
void printButtonPressed(int pressedButton) {
118-
if (pressedButton >= 0 && pressedButton < 8) {
125+
static void printButtonPressed(int pressedButton) {
126+
if ((pressedButton >= 0) && (pressedButton < 8)) {
119127
(int) printf("Button pressed: %s\n", buttonLabels[pressedButton]);
120128
} else {
121129
(int) printf("Invalid button pressed\n");
122130
}
123131
}
124132

125-
void button_led_control(void)
133+
static void button_led_control(void)
126134
{
127135
uint8_t mcp23008_1_activeLEDs = 0;
128136
uint8_t mcp23008_2_previousInputs = 0;
@@ -170,7 +178,7 @@ int main(void)
170178
DELAY_milliseconds(200); // Prevent program running when programming
171179
SYSTEM_Initialize();
172180
(int) printf("Example: 3. I2C IO Expander 2 - LEDs and Buttons, Implementation: Polled, Visualization: Printf \r\n");
173-
(int) printf("MCU Device family: PIC18F/18F \r\n");
181+
(int) printf("MCU Device family: PIC18 \r\n\r\n");
174182
(int) printf("Press Curiosity Nano Explorer touch buttons and use Joystick to turn off all LEDS. Press SW0 on Curiosity Nano to exit. \r\n");
175183
button_led_control();
176184

pic18f57q43-i2c-io-expander2-leds-buttons-polled-printf.X/mcc-manifest-autosave.yml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22

33
manifest_file_version: 1.0.0
44
project: pic18f57q43-i2c-io-expander2-leds-and-buttons-polled-printf
5-
creation_date: 2025-04-14T11:20:52.416+02:00[Europe/Berlin]
5+
creation_date: 2025-10-17T12:15:58.144+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.a
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/i2c-host-driver', type: MELODY, version: 1.0.5}
21+
- {name: '@mchp-mcc/pic18-pin-manager', type: MELODY, version: 3.7.1}
2022
- {name: '@mchp-mcc/delay-blocking-driver', type: MELODY, version: 3.2.0}
21-
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.0}
22-
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.1.0-dev.1}
23-
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
24-
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.29.2-dev.1}
2523
- {name: '@mchp-mcc/pic18-configuration-bits-v1', type: MELODY, version: 5.3.5}
26-
- {name: '@mchp-mcc/pic18-pin-manager', type: MELODY, version: 3.7.1}
27-
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.9.1-feat.6}
28-
- {name: '@mchp-mcc/scf-pic8-i2c-v1', type: MELODY, version: 6.1.4}
29-
- {name: '@mchp-mcc/scf-pic8-interrupt-v1', type: MELODY, version: 5.2.11}
24+
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.1}
3025
- {name: '@mchp-mcc/scf-pic8-osc-v1', type: MELODY, version: 4.4.0}
31-
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.2.0}
26+
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
3227
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}
28+
- {name: '@mchp-mcc/scf-pic8-interrupt-v1', type: MELODY, version: 5.2.11}
29+
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.2.1}
30+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.11.0}
31+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.29.1}
32+
- {name: '@mchp-mcc/scf-pic8-i2c-v1', type: MELODY, version: 6.1.4}
33+
- {name: '@mchp-mcc/melody', type: CLASSIC, version: 2.10.0}
34+
- {name: '@mchp-mcc/pic-8bit', type: MELODY, version: 5.29.1}
35+
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.0.5}
36+
- {name: '@mchp-mcc/scf-pic8-uart-v1', type: MELODY, version: 7.2.1}

0 commit comments

Comments
 (0)