Skip to content

Commit 45788f0

Browse files
committed
MPAE-19433 mplab project created and tested, working as expected
1 parent 1f45cfc commit 45788f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+7124
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Please do not change this logo with link -->
1+
<!-- MPAE-19433 Please do not change this logo with link -->
22

33
<a target="_blank" href="https://www.microchip.com/" id="top-of-page">
44
<picture>
@@ -8,7 +8,17 @@
88
</picture>
99
</a>
1010

11-
# Update the title for avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors here
11+
# AVR128DB48 I2C_Host Example Component for CNano Explorer: Find all I2C Clients on Bus (Callbacks, Printf-errors)
12+
The following is the output, when Printf is selected as the Visualization Output.
13+
14+
![alt text](images/Find_all_i2c_clients_callbacks_printf_avrDB.png)
15+
16+
Full confgiguration.
17+
![alt text](images/Find_all_i2c_clients_callbacks_printfErrors_avrDB_configuration.png)
18+
19+
The same configuration, when Printf with error handling is selected, generates the following output:
20+
21+
![alt text](images/Find_all_i2c_clients_callbacks_printfErrors_avrDB.png)
1222

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk

avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.X/avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.mc3

Lines changed: 284 additions & 0 deletions
Large diffs are not rendered by default.

avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.X/avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.mc3.bak0

Lines changed: 93 additions & 0 deletions
Large diffs are not rendered by default.

avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.X/avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.mc3.bak1

Lines changed: 93 additions & 0 deletions
Large diffs are not rendered by default.

avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.X/avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.mc3.bak2

Lines changed: 284 additions & 0 deletions
Large diffs are not rendered by default.

avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.X/avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors.mc3.bak3

Lines changed: 284 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
© [2025] Microchip Technology Inc. and its subsidiaries.
3+
4+
Subject to your compliance with these terms, you may use Microchip
5+
software and any derivatives exclusively with Microchip products.
6+
You are responsible for complying with 3rd party license terms
7+
applicable to your use of 3rd party software (including open source
8+
software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9+
NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10+
SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12+
WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14+
KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15+
MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16+
FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17+
TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18+
EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19+
THIS SOFTWARE.
20+
*/
21+
/**
22+
* I2C_HOST EXAMPLE Generated Driver File
23+
*
24+
* @file i2c_host example.c
25+
*
26+
* @ingroup i2c_host example
27+
*
28+
* @version I2C_HOST EXAMPLE Example Version 1.0.0
29+
*
30+
* @brief Generated file for
31+
* Example: 1. Find all I2C clients on bus
32+
* Implementation: Interrupts with callbacks
33+
* Visualization: Printf with error handling
34+
* MCU Device family: AVR
35+
*/
36+
37+
#include "mcc_generated_files/system/system.h"
38+
#include "mcc_generated_files/timer/delay.h"
39+
40+
uint8_t I2C_ProbeAll(const i2c_host_interface_t* i2cHost, uint8_t *deviceAddresses);
41+
void I2C_FindAndReportDevices(void);
42+
int main(void);
43+
44+
extern const i2c_host_interface_t* i2cHost = &I2C_Host; //TODO: If want to change I2C Host instance, update pointer to I2C Host struct
45+
46+
uint8_t I2C_ProbeAll(const i2c_host_interface_t* i2cHost, uint8_t *deviceAddresses)
47+
{
48+
uint8_t txData = 0;
49+
uint16_t txLength = 0;
50+
uint8_t devicesFound = 0;
51+
52+
for (uint8_t probeAddress = 0U; probeAddress < 0x80U; probeAddress++)
53+
{
54+
i2cHost->Write((uint16_t)probeAddress, &txData, txLength);
55+
// Wait for I2C module to be ready
56+
while (i2cHost->IsBusy())
57+
{
58+
}
59+
60+
i2c_host_error_t errorState = i2cHost->ErrorGet(); // Update errorState with the result of ErrorGet()
61+
if(errorState == I2C_ERROR_NONE)
62+
{
63+
deviceAddresses[devicesFound] = probeAddress;
64+
devicesFound++;
65+
(int) printf("Address: 0x%02X I2C_ERROR_NONE \r\n", probeAddress);
66+
IO_LED_Toggle();
67+
}
68+
else
69+
{
70+
// Handle the error appropriately
71+
switch (errorState)
72+
{
73+
case I2C_ERROR_ADDR_NACK:
74+
(int) printf("ERROR: NACK at 0x%02X\r\n", probeAddress);
75+
break;
76+
case I2C_ERROR_DATA_NACK:
77+
(int) printf("ERROR: Data NACK at 0x%02X\r\n", probeAddress);
78+
break;
79+
case I2C_ERROR_BUS_COLLISION:
80+
(int) printf("ERROR: Bus Collision at 0x%02X\r\n", probeAddress);
81+
break;
82+
default:
83+
(int) printf("ERROR: Unknown at 0x%02X\r\n", probeAddress);
84+
break;
85+
}
86+
}
87+
}
88+
(int) printf("End potential I2C bus addresses\r\n\r\n");
89+
return devicesFound;
90+
}
91+
92+
void I2C_FindAndReportDevices(void)
93+
{
94+
uint8_t devicesFound = 0;
95+
uint8_t deviceAddresses[128];
96+
97+
devicesFound = I2C_ProbeAll(i2cHost, deviceAddresses);
98+
99+
(int) printf("\r\nDevices found = %u \r\n", devicesFound);
100+
101+
for (uint8_t i = 0; i < devicesFound; i++)
102+
{
103+
(int) printf("0x%02X ", deviceAddresses[i]);
104+
}
105+
(int) printf("\r\n\r\n");
106+
IO_LED_SetLow(); //Turn LED on once all I2C Clients are found (assuming active low LED);
107+
}
108+
109+
int main(void)
110+
{
111+
DELAY_milliseconds(200); // Prevent program running when programming
112+
113+
SYSTEM_Initialize();
114+
115+
(int) printf("Example: 1. Find all I2C clients on bus, Implementation: Interrupts with callbacks, Visualization: Printf with error handling\r\n\r\n");
116+
(int) printf("Looking for all devices on i2cHost\r\n");
117+
I2C_FindAndReportDevices();
118+
119+
while(1){}
120+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
2+
3+
manifest_file_version: 1.0.0
4+
project: avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors
5+
creation_date: 2025-04-10T12:56:46.868+02:00[Europe/Berlin]
6+
operating_system: Windows 11
7+
mcc_mode: IDE
8+
mcc_mode_version: v6.25
9+
device_name: AVR128DB48
10+
compiler: XC8 3.00
11+
mcc_version: 5.5.2
12+
mcc_core_version: 5.7.1
13+
content_manager_version: 5.0.1
14+
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: AVR-Dx_DFP, version: 2.7.321}
19+
modules:
20+
- {name: '@mchp-mcc/avr-8bit', type: MELODY, version: 4.13.0}
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}
30+
- {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}
32+
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file has been autogenerated by MPLAB Code Configurator. Please do not edit this file.
2+
3+
manifest_file_version: 1.0.0
4+
project: avr128db48-find-all-i2c-clients-on-bus-callback-printf-errors
5+
creation_date: 2025-04-10T12:56:46.838+02:00[Europe/Berlin]
6+
operating_system: Windows 11
7+
mcc_mode: IDE
8+
mcc_mode_version: v6.25
9+
device_name: AVR128DB48
10+
compiler: XC8 3.00
11+
mcc_version: 5.5.2
12+
mcc_core_version: 5.7.1
13+
content_manager_version: 5.0.1
14+
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: AVR-Dx_DFP, version: 2.7.321}
19+
modules:
20+
- {name: '@mchp-mcc/avr-8bit', type: MELODY, version: 4.13.0}
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}
30+
- {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}
32+
- {name: '@mchp-mcc/uart-driver', type: MELODY, version: 1.10.2}

0 commit comments

Comments
 (0)