Skip to content

Commit 6bb91ac

Browse files
committed
MPAE-19435 project working, readme and main-meta updated
1 parent 139ad9c commit 6bb91ac

17 files changed

+231
-152
lines changed

.main-meta/main.json

Lines changed: 24 additions & 9 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.avr128db48-i2c-io-expander1-leds-polled-printf",
7-
"version": " ",
8-
"displayName": "",
7+
"version": "1.0.0",
8+
"displayName": "avr128db48-i2c-io-expander1-leds-polled-printf",
99
"projectName": "avr128db48-i2c-io-expander1-leds-polled-printf",
1010
"shortDescription": "LED chaser increments binary on 6 LEDs every 100 ms. When all on, toggles 8 LEDs every sec. Polled with Delay driver, shows hex/binary of I/O expander pins via UART printf.",
1111
"ide": {
@@ -18,13 +18,13 @@
1818
"semverRange": "^3.0.0"
1919
}
2020
],
21-
"dfp": {
22-
"name": "",
23-
"semverRange": ""
21+
"dfp": {
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: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,59 @@
1010

1111
# AVR128DB48 I2C_Host Example Component for CNano Explorer: I/O Expander 1 LEDs (Polled, Printf)
1212

13-
The following is the output for this example.
14-
Notice the delta 103 ms in the B and the 1.21 s in the C columns, respectively of the time plot. The difference from 100 ms, is simply due to the positioning of the cursor.
13+
The [I<sup>2</sup>C Host IO Expander 1 - LEDs Example](https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=I2C.HOST.EX.RUNNING.I2C.HOST.IOEXPANDER1.LEDS&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.
1516

16-
![alt text](images/avr128db48-i2c-io-expander1-leds-polled-printf_avrDB.png)
17+
![alt text](images\avr128db48-i2c-io-expander1-leds-polled-printf_avrDB_intro.png)
1718

18-
The MCC Melody configuration is as shown in the following image.
19+
The example implements an LED chaser, incrementing the binary number on the lower six LEDs every 100 ms. Once the six active-low LEDs are all on, the pattern changes to toggle all eight LEDs every second.
1920

20-
![alt text](images/avr128db48-i2c-io-expander1-leds-polled-printf_avrDB_configuration.png)
21+
The polled implementation simply uses a delay, first of 100 ms then the delay period is changed to 1s once the LED chaser is finished. The hex and binary values of the I/O expander pins are displayed as a printf message over the Universal Asynchronous Receiver and Transmitter (UART).
2122

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

26+
![alt text](images/avr128db48-i2c-io-expander1-leds-polled-printf_avrDB.png)
27+
**Note:** the delta 103 ms in the B and the 1.21 s in the C columns, respectively of the time plot. The difference from 100 ms, is simply due to the positioning of the cursor.
2328

24-
<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
29+
## Setup
30+
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.
2531

26-
## Related Documentation
32+
![alt text](images/avr128db48-i2c-io-expander1-leds-polled-printf_avrDB_configuration.png)
33+
![alt text](images/avr128db48-i2c-io-expander1-leds-polled-printf_avrDB_configuration_pins.png)
2734

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

33-
## Software Used
3436

35-
<!-- All software used in this example must be listed here. Use unbreakable links!
36-
- MPLAB® X IDE 5.30 or newer [(microchip.com/mplab/mplab-x-ide)](http://www.microchip.com/mplab/mplab-x-ide)
37-
- MPLAB® XC8 2.10 or a newer compiler [(microchip.com/mplab/compilers)](http://www.microchip.com/mplab/compilers)
38-
- MPLAB® Code Configurator (MCC) 3.95.0 or newer [(microchip.com/mplab/mplab-code-configurator)](https://www.microchip.com/mplab/mplab-code-configurator)
39-
- 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)
40-
- Microchip PIC18F-Q Series Device Support (1.4.109) or newer [(packs.download.microchip.com/)](https://packs.download.microchip.com/) -->
37+
## MCC Melody Example Components
38+
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.
4139

42-
- 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)
43-
- 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)
4440

45-
## Hardware Used
41+
## Related Documentation
4642

47-
<!-- All hardware used in this example must be listed here. Use unbreakable links!
48-
- PIC18F47Q10 Curiosity Nano [(DM182029)](https://www.microchip.com/Developmenttools/ProductDetails/DM182029)
49-
- Curiosity Nano Base for Click boards™ [(AC164162)](https://www.microchip.com/Developmenttools/ProductDetails/AC164162)
50-
- POT Click board™ [(MIKROE-3402)](https://www.mikroe.com/pot-click) -->
43+
- [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")
44+
- [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")
5145

52-
## Setup
46+
- [Curiosity Nano Explorer User Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/AVR128DB48-Curiosity-Nano-HW-UserGuide-DS40002186B.pdf "Curiosity Nano Explorer Users Guide")
5347

54-
<!-- 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 -->
48+
- [AVR128DB48 Data Sheet](https://ww1.microchip.com/downloads/en/DeviceDoc/AVR128DB28-32-48-64-DataSheet-DS40002247A.pdf "AVR128DB48 Data Sheet")
5549

56-
## Operation
50+
## Software Used
51+
- [MPLAB® X IDE](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide) v6.25 or newer
52+
- [MPLAB® XC8](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8) v3.00 or newer
53+
54+
- [MPLAB® Code Configurator](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator) (MCC) Plug-in Version v5.6.2 or newer (*Tools>Plugins>Installed*, search: "MCC")
55+
- [MPLAB® Data Visualizer](https://www.microchip.com/en-us/tools-resources/debug/mplab-data-visualizer) Plug-in Version v1.4.1926 or newer (*Tools>Plugins>Installed*, search: "Data Visualizer")
56+
- MCC Melody I2C_Host Example Component for the Curiosity Nano Explorer 1.0.0 or newer
57+
- MCC Core v5.8.2 or newer
58+
- Single Page Application (SPA) Host v1.0.0 or newer
59+
- MCC Melody Core v2.9.1 or newer
5760

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

60-
## Summary
63+
![alt text](images/MCC_Core_ContentLibrary_Versions_SPA.png)
64+
65+
## Hardware Used
66+
- AVR128DB48 Curiosity Nano [(EV35L43A)](https://www.microchip.com/en-us/development-tool/EV35L43A)
67+
- Curiosity Nano Explorer [(EV58G97A)](https://www.microchip.com/en-us/development-tool/EV58G97A)
6168

62-
<!-- Summarize what the example has shown -->

avr128db48-i2c-io-expander1-leds-polled-printf.X/avr128db48-i2c-io-expander1-leds-polled-printf.mc3

Lines changed: 43 additions & 19 deletions
Large diffs are not rendered by default.

avr128db48-i2c-io-expander1-leds-polled-printf.X/main.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
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: 2. I2C IO Expander 1 - LEDs
@@ -40,91 +40,99 @@
4040
// MCP23008 register addresses are in Table 1-2 (page 5) of the data sheet
4141
// The Curiosity Nano Explorer (EV58G97A) has 2 x MCP23008 IO Expanders
4242

43-
#define MCP23008_1_I2C_ADDRESS ((uint8_t)0x25)
43+
#define MCP23008_1_I2C_ADDRESS ((uint8_t)0x25)
4444
#define MCP23008_REG_ADDR_IODIR 0x00
4545
#define MCP23008_REG_ADDR_GPIO 0x09
4646
#define PINS_DIGITAL_OUTPUT 0x00
4747
#define PINS_DIGITAL_HIGH 0xFF
48+
#define PINS_DIGITAL_LOW 0x00
4849
#define DATALENGTH 2
50+
#define I2C_ERROR_NONE 0
4951

5052
extern void DELAY_milliseconds(uint16_t milliseconds);
53+
static uint8_t MCP23008_Write(uint8_t address, uint8_t reg, uint8_t data);
54+
static void to_binary(uint8_t num, char *str);
55+
static uint16_t led_row_counter(void);
5156

52-
uint8_t errorState = I2C_ERROR_NONE;
53-
uint8_t *data;
54-
uint8_t *data_length;
55-
uint8_t pins = 0;
56-
char binaryStr[9]; // 8 bits + null terminator
57+
static i2c_host_error_t errorState = I2C_ERROR_NONE;
58+
static uint8_t *data;
59+
static uint8_t *data_length;
60+
static uint8_t pins = 0;
61+
static char binaryStr[9]; // 8 bits + null terminator
5762

58-
uint8_t MCP23008_Write(uint8_t address, uint8_t reg, uint8_t data)
63+
static uint8_t MCP23008_Write(uint8_t address, uint8_t reg, uint8_t data)
5964
{
60-
uint8_t errorState = I2C_ERROR_NONE;
6165
size_t txLength = 2;
62-
uint8_t txBuffer[2] = {};
66+
uint8_t txBuffer[2] = {0};
6367

6468
txBuffer[0] = reg;
6569
txBuffer[1] = data;
6670

67-
uint8_t waitCounter = 100;
6871
if(I2C_Host.Write(MCP23008_1_I2C_ADDRESS, txBuffer, txLength))
6972
{
70-
while (I2C_Host.IsBusy() && waitCounter--)
73+
uint8_t waitCounter = 100;
74+
while(!I2C_Host.IsBusy())
75+
{
76+
//Wait here until I2C bus can start transmitting
77+
}
78+
while (I2C_Host.IsBusy() && (waitCounter > 0U))
7179
{
7280
I2C_Host.Tasks();
81+
waitCounter--;
7382
}
7483
}
7584

7685
errorState = I2C_Host.ErrorGet();
7786
return errorState;
7887
}
7988

80-
// Function to convert a number to a binary string
81-
void to_binary(uint8_t num, char *str)
89+
static void to_binary(uint8_t num, char *str)
8290
{
83-
for (int i = 7; i >= 0; i--)
84-
{
85-
str[7 - i] = (num & (1 << i)) ? '1' : '0';
91+
for (uint8_t i = 0U; i < 8U; i++) {
92+
str[7U - i] = ((num & (uint8_t)(1U << (7U - i))) != 0U) ? '1' : '0';
8693
}
8794
str[8] = '\0'; // Null-terminate the string
8895
}
8996

90-
uint16_t led_row_counter(void)
97+
static uint16_t led_row_counter(void)
9198
{
92-
for (pins = 0; pins < 64; pins++)
99+
for (pins = 0; pins < 64U; pins++)
93100
{
94101
// Invert the pins, since using pins 8 to 3, which are active low
95102
uint8_t pins_inverted = ~(pins << 2);
96103
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins_inverted);
97104

98105
to_binary(pins_inverted, binaryStr);
99-
printf("LED state: 0x%02X 0b%s\n", pins_inverted, binaryStr);
106+
(int) printf("LED state: 0x%02X 0b%s\n", pins_inverted, binaryStr);
100107
IO_LED_Toggle();
101108
IO_Debug_Toggle();
102109
DELAY_milliseconds(100);
103110
}
104-
printf("\r\n");
111+
(int) printf("\r\n");
105112
return errorState;
106113
}
107114

108115
int main(void)
109116
{
110117
DELAY_milliseconds(200); // Prevent program running when programming
111118
SYSTEM_Initialize();
112-
printf("Example: 2. I2C IO Expander 1 - LEDs, Implementation: Polled, Visualization: Printf\r\n");
113-
printf("Note: LEDs are assumed to be active LOW.\r\n");
119+
(int) printf("Example: 2. I2C IO Expander 1 - LEDs, Implementation: Polled, Visualization: Printf\r\n");
120+
(int) printf("MCU Device family: AVR \r\n\r\n");
121+
(int) printf("Note: LEDs are assumed to be active LOW.\r\n");
114122

115123
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_IODIR, PINS_DIGITAL_OUTPUT);
116124

117125
errorState = led_row_counter();
118126
DELAY_milliseconds(1000);
119127

120-
pins = 0xFF; // Turn off active LOW LEDs
128+
pins = (uint8_t) 0xFF; // Turn off active LOW LEDs
121129
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins);
122130

123131
while(1)
124132
{
125133
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins);
126134
to_binary(pins, binaryStr);
127-
printf("LED state: 0x%02X 0b%s \r\n", pins, binaryStr);
135+
(int) printf("LED state: 0x%02X 0b%s \r\n", pins, binaryStr);
128136
IO_LED_Toggle();
129137
IO_Debug_Toggle();
130138
DELAY_milliseconds(1000);

avr128db48-i2c-io-expander1-leds-polled-printf.X/mcc-manifest-autosave.yml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,39 @@
22

33
manifest_file_version: 1.0.0
44
project: avr128db48-i2c-io-expander1-leds-polled-printf
5-
creation_date: 2025-04-10T13:17:13.120+02:00[Europe/Berlin]
5+
creation_date: 2025-10-20T16:05:47.927+02:00[Europe/Berlin]
66
operating_system: Windows 11
77
mcc_mode: IDE
88
mcc_mode_version: v6.25
99
device_name: AVR128DB48
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.9.0-feat.24}
18-
packs: {name: AVR-Dx_DFP, version: 2.7.321}
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/avr-8bit', type: MELODY, version: 4.13.1-dev.4}
21-
- {name: '@mchp-mcc/avr8-configuration-bits-v1', type: MELODY, version: 4.3.0}
22-
- {name: '@mchp-mcc/avr8-pin-manager', type: MELODY, version: 4.6.1}
23-
- {name: '@mchp-mcc/delay-blocking-driver', type: MELODY, version: 3.2.0}
24-
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.0}
25-
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.1.0-dev.1}
26-
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
27-
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.9.1-feat.6}
28-
- {name: '@mchp-mcc/scf-avr8-clkctrl-v3', type: MELODY, version: 2.1.0-dev.1}
29-
- {name: '@mchp-mcc/scf-avr8-interrupt-v1', type: MELODY, version: 5.0.13-dev.1}
3020
- {name: '@mchp-mcc/scf-avr8-twi-v1', type: MELODY, version: 8.2.0}
31-
- {name: '@mchp-mcc/scf-avr8-usart-v1', type: MELODY, version: 10.2.1}
21+
- {name: '@mchp-mcc/avr8-pin-manager', type: MELODY, version: 4.6.2}
22+
- {name: '@mchp-mcc/scf-avr8-clkctrl-v3', type: MELODY, version: 2.0.10}
23+
- {name: '@mchp-mcc/delay-blocking-driver', type: MELODY, version: 3.2.0}
24+
- {name: '@mchp-mcc/scf-avr8-interrupt-v1', type: MELODY, version: 5.0.12}
25+
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.0.5}
26+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.11.0}
3227
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}
28+
- {name: '@mchp-mcc/avr8-configuration-bits-v1', type: MELODY, version: 4.3.0}
29+
- {name: '@mchp-mcc/scf-avr8-usart-v1', type: MELODY, version: 10.3.1}
30+
- {name: '@mchp-mcc/avr-8bit', type: MELODY, version: 4.14.2}
31+
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.1}
32+
- {name: '@mchp-mcc/main-manager', type: MELODY, version: 3.1.2}
33+
- {name: '@mchp-mcc/example-i2c-host', type: MELODY, version: 1.0.1}
34+
- {name: '@mchp-mcc/scf-avr8-interrupt-v1', type: MELODY, version: 5.0.12}
35+
- {name: '@mchp-mcc/avr8-pin-manager', type: MELODY, version: 4.6.2}
36+
- {name: '@mchp-mcc/scf-avr8-usart-v1', type: MELODY, version: 10.3.1}
37+
- {name: '@mchp-mcc/pin-content-processor', type: MELODY, version: 3.11.0}
38+
- {name: '@mchp-mcc/i2c-host-driver', type: MELODY, version: 1.0.5}
39+
- {name: '@mchp-mcc/scf-avr8-clkctrl-v3', type: MELODY, version: 2.0.10}
40+
- {name: '@mchp-mcc/avr-8bit', type: MELODY, version: 4.14.2}

0 commit comments

Comments
 (0)