PIC I2C library problem - Page 1
Forum section: electronics / general

author: alanb
author_rank: Frequent Contributor
timestamp: January 22, 2014, 04:39:59 pm
content: I may be doing something very stupid but I would be grateful if someone could point me in the right direction.I have included#include <I2C.h>the line OpenI2C(MASTER, SLEW_OFF); generateserror: 'MASTER' undeclared (first use in this function)error: 'SLEW_OFF' undeclared (first use in this function)I had assumed that MASTER and SLEW_OFF were constants that would be defined in the header, but a text search of I2C.h shows that they are not there.I am using the XC16(v1.21) complier in MPLAB X v2.00 and the device is a dsPIC30F4011.I would be grateful for any advice.

author: dannyf
author_rank: Super Contributor
timestamp: January 22, 2014, 04:51:00 pm
content: pointless and unhelpful post removed by moderator

author: alanb
author_rank: Frequent Contributor
timestamp: January 22, 2014, 04:54:43 pm
content: I2C.h is a standard Microchip header so my assumption is that I'm doing something wrong or alternatively if there was an error in the header it would have been fixed by now and a revised version released.

author: dannyf
author_rank: Super Contributor
timestamp: January 22, 2014, 05:17:21 pm
content: pointless and unhelpful response removed by moderator, there is pointing in the right direction and there is taking the piss !

author: alanb
author_rank: Frequent Contributor
timestamp: January 22, 2014, 05:20:02 pm
content: To rephrase the question; What am I doing wrong?

author: ElektroQuark
author_rank: Unknown
timestamp: January 23, 2014, 09:58:57 am
content: Using not defined definitions

author: alanb
author_rank: Frequent Contributor
timestamp: January 23, 2014, 10:01:36 am
content: Quote from: EdoNork on January 23, 2014, 09:58:57 amAny Idea what the values for MASTER and SLEW_OFF should be?

author: SPRX
author_rank: Regular Contributor
timestamp: January 23, 2014, 10:44:47 am
content: on the ' OpenI2C(MASTER, SLEW_OFF) ' function, MASTER must be 0x8000 ( I2C module enabled)and SLEW_OFF must be the Baud Rate Generator (I2CxBRG), which is I2CxBRG = (FCY/FSCL – FCY/10,000,000) – 1If you refer to your processor's datasheet, BRG is explained in the I2c section .Correction:-Actually, for the dsPIC30F4011 processor;I2CBRG = (FCY/FSCL – FCY/1,111,111) – 1 (just referred to your processor datasheet)and MASTER must be 0xFFFF

author: alanb
author_rank: Frequent Contributor
timestamp: January 23, 2014, 11:03:23 am
content: Thank you SPRX I will try that when I return home this evening.

author: SPRX
author_rank: Regular Contributor
timestamp: January 23, 2014, 11:10:20 am
content: Actually, for the dsPIC30F4011 processor;I2CBRG = (FCY/FSCL – FCY/1,111,111) – 1 (just referred to your processor datasheet)and MASTER must be 0xFFFF

author: Dreso12
author_rank: Contributor
timestamp: January 23, 2014, 11:23:55 am
content: Hi,Normally all this definitions are already done and somewhere in the MPLAB include directories, maybe if you include the dsPIC30F4011.h (not sure about the exact name) all these definitions will be there, look for the include file in the MPLAB/include... folder of your computer.

author: dannyf
author_rank: Super Contributor
timestamp: January 23, 2014, 12:02:40 pm
content: QuoteThe answer is right in front of you.Someone may be able to point out for you the right answer. However, if you don't learn to read the datasheet, compiler manual and header files, you will run into similar problems sooner or later.I would suggest that you learn to do things the right way, rather than learn the particular answer to this particular problem.

author: Simon
author_rank: Unknown
timestamp: January 23, 2014, 05:22:36 pm
content: Quote from: dannyf on January 23, 2014, 12:02:40 pmFrom my experience of pic things are so poorly explained probably by people just like you that unless you are really talented at programming you can never work it out. That is why I use arduino because the key to using pics is so stupidly buried that I can't be bothered to find it ! why don't you explain the nature of the error rather than the direct solution in keeping with your "ethics", then you would be helpful instead of just being a clever dick !

author: diyaudio
author_rank: Frequent Contributor
timestamp: January 24, 2014, 09:07:57 pm
content: Quote from: alanb on January 22, 2014, 04:39:59 pmTry to add the full path to the X16 complier in my case I had a similar issue with the XC8 with the SPI headers not resolving.

author: TooOldForThis
author_rank: Regular Contributor
timestamp: January 25, 2014, 02:35:10 am
content: It's not clear to me if the OP is seeing the errors in the compiler output or in the editor.The MPlabX IDE tries to parse all the symbols in the source code, but it doesn't do a very good job.Typically you include xc.h in your source code file. The xc.h file uses conditional compilation based on the CPU type to pull in all the definitions and library functions that apply to that CPU.The problem is that the CPU type is supplied to the compiler as a command line argument, its not defined in the source code. Therefore the IDE doesn't know how to navigate the conditional compilations of the Microchip supplied header files. The IDE says there's undefined symbols left and right - but when you hit the compile button, it compiles fine.So I ignore all the red exclamation marks and wavy red lines in the editor window - they are wrong more than they are right.You only have to fix things if the actual compiler says something is wrong.

author: manny87
author_rank: Newbie
timestamp: January 27, 2014, 06:03:53 pm
content: hiI encounter the same problem with a pic18f14k50. if you trace the include files:XC.h -> htc.h -> pic18.h -> pic_chip_select.h (in my case)opening the files, hold down the Ctrl key and click the file nameyou will probably find that your chip's h file is grayed-out like the rest of the chips.if so you can fix this by adding the next line as the first line in you main c file."define _18f14k50"good luck