2020/01/24 05:47:00
Hi there, I am trying to prototype a PIC16F data collection device on a Curiosity board - and am a  newbie C programmer (learnt my programming in Assembler in the 70's! I have done some Assembler programming on PIC, but decided to go to C for this project....so think "first timer"!).
I am using MPLAB X IDE (current version) and utilising MCC to create drivers/headers/config. (windows 10 Pro).
The plan is to configure board as I2C Slave to pass collected data to Pi data processor. (I2C Master).
The application is (obvs) real-time, so I am wanting to use Interrupt based solution.
The problem I am having is trying to understand the API provided by the I2C drivers. e.g. MCC provides files under the headings "i2c_driver" and "i2c_slave".. there are many entrypoints, but no apparent guidance as to which to use. I have spent some days (weeks?) searching, and while I have found some examples and tutorials they do not seem compatible with the code generated by MCC...
A steer, code example, guidance, pointer to docs or even sympathy would help... I do not want to go bit-banging, or attempting to write my own libraries, and would prefer to utilise the Microchip generated ones...
thanks in advance :-/
2020/01/24 05:49:35
PS... AN734 has a link to code examples which appear to be exactly what I need - but the link is broken - <sad face>
2020/01/24 07:16:29
Although AN734, AN735 and AN736  are about the subject, and contain explainations and example code,
They are Not about MCC, and code is very different from what is generated by MCC.
The application notes are here:
The rest of this message is about Master mode, so may be beside the original question.
There is a lot of example code in the Click Library collection in MCC,
using the Foundation Services library in MCC.
The Foundation Services driver code in MCC is the forerunner for the current code,
generated by Device library PIC10/PIC12/PIC16/PIC18 v1.78.1
in the current release of MCC.
While there is a lot of example code hidden around, there is little in the way of description and documentation.
There are some comments and example/test code in this thread:
If you skip the EEPROM example and test code in projects in that thread,
there is also example code of a I2C Bus scan, reporting which slave devices respond when addressed.
The thread is however not a tutorial, instead it is mostly pointing out areas that could be improved.
Here is another thread that may be relevant:
2020/01/24 07:35:44
Try to use use the I2C PIC10, PIC12, PIC16 PIC18 library instead of the foundation library, the i2c.h file has some short descriptions how to use those generated functions.
Microchip developer help page has some few tutorials you could start with. MPLAB Xpress example page.
You could also check this tutorial.
2020/01/24 08:05:54
Mysil, thank you very for your attempt to provide assistance....
But I am not managing to unravel this...
For example, your memory test examples call routines like EEPROM_ReadOneByte  which don't exist in the I2C Slave implementations provided by MCC (and I understand that is obvious), but I can't decide which routines in the drivers MCC provides for the MSSP Slave implementation. should be used..
For example I was expecting a function to be available of the form "I2C_Initialise()", but there is not - I can find "I2C_driver_open()" and "i2c_slave_open()" but which do I use, and are these really replacements for an "Initialize" function?
It seems most examples are Master, and not Interrupt driven and are focussed on using EEProms, so they are just too far away from what I am trying to do.
I was expecting to provide a main that did something like this:-
void main(void)
char data;
data= 0;
while(something);  //wait for master to try to read me
... but how do I declare and write the ISR (or is this provided somewhere)....
FYI I am attempting to use the "MSSP (Foundation Services Library by Microchip)".
Maybe I am just missing too much here, and should slope off and do something else with my time,  but it would be good to get started :-(
Thanks again,
2020/01/24 08:08:23
Try to use use the I2C PIC10, PIC12, PIC16 PIC18 library instead of the foundation library, the i2c.h file has some short descriptions how to use those generated functions.
Microchip developer help page has some few tutorials you could start with. MPLAB Xpress example page.
You could also check this tutorial.

Katela, thank you for this suggestion, I will give that a try....
2020/01/24 13:37:53
To katela,
You will have to be more precise about what version of
MCC Device Library for PIC10, PIC12, PIC16, PIC18 MCUs 
that you suggest to use.
There is a big rewrite going on for the MSSP drivers for I2C and SPI in device library 1.78.0 and 1.78.1,
and generated code is wery different from previous versions of the library.
EEPROM_...     functions  are generated by memoryProductsLibrary_v2.10.jar,
as is pointed out several places in the thread, and in source code in the MemoryLibraryTest_3.zip
Yes,  example code generated by memoryProductsLibrary_v2.10  
make calls to functions that don't exist in EEPROM_driver.c 
But  memoryProductsLibrary_v2.10    is all Master code, and doesn't answer your call for Slave code example.
I have seen the  I2C Slave code generated by device library 1.78.0
and did not understand how to use it either,
so continue to use code based on code generated by previous versions of MCC device library.
2020/01/24 14:12:43
You are correct Mysil, the examples I am referring to would work with the MCC Device Library PIC10, PIC12, PIC16, PIC18 version 1.77
I have realized from 1.78 it's a different beast. 
If the OP doesn't mind, who could load the older version (in MCC versions (bottom left) just expand the required library you will see a number of versions. Right-click and select mark for load), it's less obscure than the foundation library and at least there are some few examples online he can get started with while learning the new version. 
2020/01/25 09:45:11
thanks guys - I will make sure I have the right libraries version included - while I haven't got it working yet, at least the MCC files and examples made some sense...
I also realised that in my "tinkering" I had also manually loaded a second version of the libraries, hence the presence of i2c_slave and i2c_driver H and C files, and that was further compounding my confusion :-)
2020/01/29 06:15:43
Just a note to say that Mysil and Katela's support got me going - working with the older libraries (as opposed to Foundation Services) provided enough examples and insight to get me going. Thank you both.
I think part of the problem I was suffering was electrical. I had the Curiosity board connected to my Windows PC and powered from its usb cable. Whereas the Raspberry Pi I was using as I2C Master was powered from a separate Hub and powerbrick, and I was only connecting clock and data pins. I am guessing that there was no ground reference - in fact I think I blew the IF pins on the PI as a result... reconnecting things so that everything was powered from the Hub (and a new PI) seemed to get things working.... 
I am left with two mysteries:
 1: i2c-tools on the Pi reported two slave devices at address 0x04 and 0x044! Whereas the default PIC slave address seemed to be set to "#define I2C_SLAVE_DEFAULT_ADDRESS          0x08" ...even more wierdly I can do an i2cget() on either 04 or 044 and it works!!! Docs seem to indicate that the PI left-shifts the 7-bit address, so maybe thats related....
2: is it acceptable to link the grnd lines on the PIC to those on the PI to attempt remove the grounding problem?
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account