Discussion:
[PIC] Anyone know how to use MCC?
Neil
2018-09-16 22:36:37 UTC
Permalink
I need to add I2C functionality to existing code (18F25K42, XC8) and
some libraries for this might be nice for a change of individually
setting registers.

However, it seems that Mchip's direction on this is to install MCC, then
let MCC build the code framework their way (similar to PIC32 code
w/Harmony).
Assuming I'm willing to do that (not sure I am yet), I installed the MCC
plugin, but can't find API docs. Google results indicate that there is
some documentation in the code, but there really isn't. For example, I
have the ADC module setup, but there's nothing that tells me what to
call to select and sample a channel, how to determine completion and
extract the result, etc.

Alternatively, can I just include and access the MCC libraries directly
from my own code? If so, where is MCC even installed?

Cheers,
-Neil.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Brent Brown
2018-09-16 23:44:23 UTC
Permalink
Hi Neil,

Have recently gone down the same track, 18LF46K22, MCC & XC8. It took some
time/effort to figure things out, but between the .c and .h files there is kindof enough
info to figure out how they work. I agree it could be easier. After some trial & error it
started to fall into place somewhat and I could appreciate that MCC was actually
being helpful. Examples:

result = ADC_GetConversion(6); // Get ADC result, channel 6

#define MCP23017 0x20 // I2C address of MCP23017 16bit I/O expander
unsigned char somedata[12] = { 0x00, // Starting from register address 0
0xFF, // IODIRA - Direction A all inputs
0x01, // IODIRB - Direction B one input
0x00, // IPOLA - Input polarity A
0x00, // IPOLB - Input polarity B
0xFF, // GPINTENA - Interrupt on change A, 8 inputs
0x01, // GPINTENB - Interrupt on change B, 1 input
0xFF, // DEFVALA - Default value compare A
0xFF, // DEFVALB - Default value compare B
0xFF, // INTCONA - Interrupt A use DEFVAL
0xFF, // INTCONB - Interrupt B use DEFVAL
0x40 }; // IOCON - INT pins OR'ed
I2C1_MasterWrite(somedata, 12, MCP23017, &I2C_Wflag); // Send 12 bytes of
data to I2C chip to initialize

command = 0x12; // Request key status (inputs)
length = 1; // from I2C port expander chip
I2C1_MasterWrite(&command, length, MCP23017, &I2C_Wflag);
__delay_us(10);
I2C1_MasterRead(I2Cdata, 2, MCP23017, &I2C_Rflag); // Returned data is in
I2Cdata[0] and I2Cdata[1]
Post by Neil
I need to add I2C functionality to existing code (18F25K42, XC8) and
some libraries for this might be nice for a change of individually
setting registers.
However, it seems that Mchip's direction on this is to install MCC, then
let MCC build the code framework their way (similar to PIC32 code
w/Harmony).
Assuming I'm willing to do that (not sure I am yet), I installed the MCC
plugin, but can't find API docs. Google results indicate that there is
some documentation in the code, but there really isn't. For example, I
have the ADC module setup, but there's nothing that tells me what to
call to select and sample a channel, how to determine completion and
extract the result, etc.
Alternatively, can I just include and access the MCC libraries directly
from my own code? If so, where is MCC even installed?
Cheers,
-Neil.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Neil
2018-09-17 02:27:34 UTC
Permalink
Thanks Brent. I'm looking through some of the files it's created and
the function nams seem to be self-explanatory, though I wonder if I'll
have to decipher their code to figure out details.
Time is of the essence, but I think I'll risk it.

Cheers,
-Neil.
Post by Brent Brown
Hi Neil,
Have recently gone down the same track, 18LF46K22, MCC & XC8. It took some
time/effort to figure things out, but between the .c and .h files there is kindof enough
info to figure out how they work. I agree it could be easier. After some trial & error it
started to fall into place somewhat and I could appreciate that MCC was actually
result = ADC_GetConversion(6); // Get ADC result, channel 6
#define MCP23017 0x20 // I2C address of MCP23017 16bit I/O expander
unsigned char somedata[12] = { 0x00, // Starting from register address 0
0xFF, // IODIRA - Direction A all inputs
0x01, // IODIRB - Direction B one input
0x00, // IPOLA - Input polarity A
0x00, // IPOLB - Input polarity B
0xFF, // GPINTENA - Interrupt on change A, 8 inputs
0x01, // GPINTENB - Interrupt on change B, 1 input
0xFF, // DEFVALA - Default value compare A
0xFF, // DEFVALB - Default value compare B
0xFF, // INTCONA - Interrupt A use DEFVAL
0xFF, // INTCONB - Interrupt B use DEFVAL
0x40 }; // IOCON - INT pins OR'ed
I2C1_MasterWrite(somedata, 12, MCP23017, &I2C_Wflag); // Send 12 bytes of
data to I2C chip to initialize
command = 0x12; // Request key status (inputs)
length = 1; // from I2C port expander chip
I2C1_MasterWrite(&command, length, MCP23017, &I2C_Wflag);
__delay_us(10);
I2C1_MasterRead(I2Cdata, 2, MCP23017, &I2C_Rflag); // Returned data is in
I2Cdata[0] and I2Cdata[1]
Post by Neil
I need to add I2C functionality to existing code (18F25K42, XC8) and
some libraries for this might be nice for a change of individually
setting registers.
However, it seems that Mchip's direction on this is to install MCC, then
let MCC build the code framework their way (similar to PIC32 code
w/Harmony).
Assuming I'm willing to do that (not sure I am yet), I installed the MCC
plugin, but can't find API docs. Google results indicate that there is
some documentation in the code, but there really isn't. For example, I
have the ADC module setup, but there's nothing that tells me what to
call to select and sample a channel, how to determine completion and
extract the result, etc.
Alternatively, can I just include and access the MCC libraries directly
from my own code? If so, where is MCC even installed?
Cheers,
-Neil.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Loading...