Skip to content

Commit 774bca2

Browse files
committed
MPAE-19437 project working, updated readme and main-meta
1 parent a2dcc73 commit 774bca2

21 files changed

+506
-361
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-callbacks-printf",
7-
"version": " ",
8-
"displayName": "",
7+
"version": "1.0.0",
8+
"displayName": "avr128db48-i2c-io-expander1-leds-callbacks-printf",
99
"projectName": "avr128db48-i2c-io-expander1-leds-callbacks-printf",
1010
"shortDescription": "LED chaser increments binary on 6 LEDs every 100 ms. When all on, toggles 8 LEDs every sec. Uses Timer driver callbacks to switch from 100 to 1000 ms. Shows hex/binary of I/O 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: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,61 @@
1010

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

13-
The following is the output for this example.
14-
Notice the delta 99.6 ms in the B and the 1.11 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 Callbacks implementation, with the Printf visualization.
16+
17+
![alt text](images\avr128db48-i2c-io-expander1-leds-callbacks-printf_avrDB_intro.png)
18+
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.
20+
21+
The callbacks implementation uses the Timer driver. To handle the change from 100 to 1000 ms, the timer period is changed and a new timer callback is used. 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).
22+
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.
1525

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

18-
The MCC Melody configuration is as shown in the following image.
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.
1931

2032
![alt text](images/avr128db48-i2c-io-expander1-leds-callbacks-printf_avrDB_configuration.png)
2133

2234

2335

2436
<!-- This is where the introduction to the example goes, including mentioning the peripherals used -->
2537

26-
## Related Documentation
2738

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) -->
39+
## MCC Melody Example Components
40+
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.
3241

33-
## Software Used
3442

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/) -->
43+
## Related Documentation
4144

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)
45+
- [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")
46+
- [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")
4447

45-
## Hardware Used
48+
- [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")
4649

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

52-
## Setup
52+
## Software Used
53+
- [MPLAB® X IDE](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-x-ide) v6.25 or newer
54+
- [MPLAB® XC8](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc8) v3.00 or newer
5355

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 -->
56+
- [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")
57+
- [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")
58+
- MCC Melody I2C_Host Example Component for the Curiosity Nano Explorer 1.0.0 or newer
59+
- MCC Core v5.8.2 or newer
60+
- Single Page Application (SPA) Host v1.0.0 or newer
61+
- MCC Melody Core v2.9.1 or newer
5562

56-
## Operation
63+
Open the MCC Content Manager ![CM_icon](images/Icon-MPLAB-CM24.png) to verify the MCC Core and MCC Melody Core versions.
5764

58-
<!-- Explain how to operate the example. Depending on complexity, step-by-step instructions and/or tables and/or images can be used -->
65+
![alt text](images/MCC_Core_ContentLibrary_Versions_SPA.png)
5966

60-
## Summary
67+
## Hardware Used
68+
- AVR128DB48 Curiosity Nano [(EV35L43A)](https://www.microchip.com/en-us/development-tool/EV35L43A)
69+
- Curiosity Nano Explorer [(EV58G97A)](https://www.microchip.com/en-us/development-tool/EV58G97A)
6170

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

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

Lines changed: 49 additions & 22 deletions
Large diffs are not rendered by default.

avr128db48-i2c-io-expander1-leds-callbacks-printf.X/avr128db48-i2c-io-expander1-leds-callbacks-printf.mc3.bak0

Lines changed: 0 additions & 93 deletions
This file was deleted.

avr128db48-i2c-io-expander1-leds-callbacks-printf.X/avr128db48-i2c-io-expander1-leds-callbacks-printf.mc3.bak1

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© [2025] Microchip Technology Inc. and its subsidiaries.
2+
? [2025] Microchip Technology Inc. and its subsidiaries.
33
44
Subject to your compliance with these terms, you may use Microchip
55
software and any derivatives exclusively with Microchip products.
@@ -25,15 +25,14 @@
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
3232
* Implementation: Interrupts with callbacks
3333
* Visualization: Printf
3434
* MCU Device family: AVR
3535
*/
36-
3736
#include "mcc_generated_files/system/system.h"
3837
#include <util/delay.h>
3938

@@ -51,34 +50,38 @@
5150
#define DATALENGTH 2
5251
#define I2C_ERROR_NONE 0
5352

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 void TIMER_Callback_100ms(void);
56+
static void TIMER_Callback_1s(void);
57+
5458
// TODO: Replace TimerX with number of Timer chosen as dependency.
55-
// Matches name of const struct TIMER_INTERFACE, from MCC Generated Files > timer > tmrx.c
56-
static const struct TIMER_INTERFACE *Timer = &Timer1;
59+
// Matches name of const struct TIMER_INTERFACE, from MCC Generated Files > timer > tcXX.c
60+
static const struct TIMER_INTERFACE *Timer = &Timer1;
5761

5862
// TODO: Go to Header Files/MCC Generated Files/timer/tcXX.h - replace xx in TCxx_CLOCK_FREQ, e.g. TCA1_CLOCK_FREQ. ----------------------
59-
#define MS_TO_TICKS(ms) (((TCA1_CLOCK_FREQ * (ms)) / 1000UL) - 1UL)
63+
#define MS_TO_TICKS(ms) (((TCA1_CLOCK_FREQ * (ms)) / 1000UL) - 1UL)
6064
#define LED_100_MS (MS_TO_TICKS(100UL))
6165
#define LED_1000_MS (MS_TO_TICKS(1000UL))
6266

63-
uint8_t errorState = I2C_ERROR_NONE;
64-
uint8_t *data;
65-
uint8_t *data_length;
66-
uint8_t pins = 0;
67-
uint8_t pins_inverted = 0;
68-
char binaryStr[9]; // 8 bits + null terminator
67+
static i2c_host_error_t errorState = I2C_ERROR_NONE;
68+
static uint8_t *data;
69+
static uint8_t *data_length;
70+
static uint8_t pins = 0;
71+
static uint8_t pins_inverted = 0;
72+
static char binaryStr[9]; // 8 bits + null terminator
6973
static volatile bool incrementLEDs = false;
7074
static volatile bool updateLEDs = false;
7175

72-
uint8_t MCP23008_write(uint8_t address, uint8_t reg, uint8_t data)
76+
static uint8_t MCP23008_Write(uint8_t address, uint8_t reg, uint8_t data)
7377
{
74-
uint8_t errorState = I2C_ERROR_NONE;
7578
size_t txLength = 2;
76-
uint8_t txBuffer[2] = {};
79+
uint8_t txBuffer[2] = {0};
7780

7881
txBuffer[0] = reg;
7982
txBuffer[1] = data;
8083

81-
I2C_Host.Write(MCP23008_1_I2C_ADDRESS, txBuffer, txLength);
84+
I2C_Host.Write(address, txBuffer, txLength);
8285
while (I2C_Host.IsBusy())
8386
{
8487
}
@@ -88,27 +91,25 @@ uint8_t MCP23008_write(uint8_t address, uint8_t reg, uint8_t data)
8891
}
8992

9093
// Function to convert a number to a binary string
91-
void to_binary(uint8_t num, char *str)
94+
static void to_binary(uint8_t num, char *str)
9295
{
93-
for (int i = 7; i >= 0; i--) {
94-
str[7 - i] = (num & (1 << i)) ? '1' : '0';
96+
for (uint8_t i = 0U; i < 8U; i++) {
97+
str[7U - i] = ((num & (uint8_t)(1U << (7U - i))) != 0U) ? '1' : '0';
9598
}
9699
str[8] = '\0'; // Null-terminate the string
97100
}
98101

99-
void TIMER_Callback_100ms(void)
102+
static void TIMER_Callback_100ms(void)
100103
{
101104
IO_LED_Toggle();
102105
IO_Debug_Toggle();
103-
104106
incrementLEDs = true;
105107
}
106108

107-
void TIMER_Callback_1s(void)
109+
static void TIMER_Callback_1s(void)
108110
{
109111
IO_LED_Toggle();
110112
IO_Debug_Toggle();
111-
112113
updateLEDs = true;
113114
}
114115

@@ -118,30 +119,31 @@ int main(void)
118119

119120
SYSTEM_Initialize();
120121
Timer->TimeoutCallbackRegister(TIMER_Callback_100ms);
121-
printf("Example: 2. I2C IO Expander 1 - LEDs, Implementation: Interrupts with callbacks, Visualization: Printf\r\n");
122-
printf("Note: LEDs assumed to be active LOW \r\n");
122+
(int) printf("Example: 2. I2C IO Expander 1 - LEDs, Implementation: Interrupts with callbacks, Visualization: Printf\r\n");
123+
(int) printf("MCU Device family: AVR \r\n\r\n");
124+
(int) printf("Note: LEDs assumed to be active LOW \r\n");
123125

124-
errorState = MCP23008_write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_IODIR, PINS_DIGITAL_OUTPUT);
126+
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_IODIR, PINS_DIGITAL_OUTPUT);
125127

126128
while(1)
127129
{
128130
if(incrementLEDs)
129131
{
130-
if (pins < 64)
132+
if (pins < 64U)
131133
{
132134
pins_inverted = ~(pins << 2);
133-
errorState = MCP23008_write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins_inverted);
135+
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins_inverted);
134136

135137
to_binary(pins_inverted, binaryStr);
136-
printf("LED state: 0x%02X 0b%s\n", pins_inverted, binaryStr);
138+
(int) printf("LED state: 0x%02X 0b%s\n", pins_inverted, binaryStr);
137139
pins++;
138140
incrementLEDs = false;
139141
}
140142
else
141143
{
142-
printf("\r\n");
143-
pins = 0xFF; // Turn off active LOW LEDs
144-
errorState = MCP23008_write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins);
144+
(int) printf("\r\n");
145+
pins = (uint8_t) 0xFF; // Turn off active LOW LEDs
146+
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins);
145147
Timer->Stop();
146148
Timer->PeriodSet(LED_1000_MS); // Change timer period to 1s
147149
Timer->TimeoutCallbackRegister(TIMER_Callback_1s); // Change timer callback
@@ -151,12 +153,12 @@ int main(void)
151153
}
152154
if(updateLEDs)
153155
{
154-
errorState = MCP23008_write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins);
156+
errorState = MCP23008_Write(MCP23008_1_I2C_ADDRESS, MCP23008_REG_ADDR_GPIO, pins);
155157

156158
to_binary(pins, binaryStr);
157-
printf("LED state: 0x%02X 0b%s\n", pins_inverted, binaryStr);
159+
(int) printf("LED state: 0x%02X 0b%s\n", pins_inverted, binaryStr);
158160
pins = ~pins; // Toggle LEDs
159161
updateLEDs = false;
160162
}
161163
}
162-
}
164+
}

0 commit comments

Comments
 (0)