Author Topic: PIC I2C library problem  (Read 11935 times)

0 Members and 1 Guest are viewing this topic.

Offline alanbTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: gb
PIC I2C library problem
« on: January 22, 2014, 04:39:59 pm »
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); generates
error: '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.
 


 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC I2C library problem
« Reply #1 on: January 22, 2014, 04:51:00 pm »
pointless and unhelpful post removed by moderator
« Last Edit: January 23, 2014, 05:18:55 pm by Simon »
================================
https://dannyelectronics.wordpress.com/
 

Offline alanbTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: gb
Re: PIC I2C library problem
« Reply #2 on: January 22, 2014, 04:54:43 pm »
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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC I2C library problem
« Reply #3 on: January 22, 2014, 05:17:21 pm »
pointless and unhelpful response removed by moderator, there is pointing in the right direction and there is taking the piss !
« Last Edit: January 23, 2014, 05:19:47 pm by Simon »
================================
https://dannyelectronics.wordpress.com/
 

Offline alanbTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: gb
Re: PIC I2C library problem
« Reply #4 on: January 22, 2014, 05:20:02 pm »
To rephrase the question; What am I doing wrong?
 

Offline ElektroQuark

  • Supporter
  • ****
  • Posts: 1244
  • Country: es
    • ElektroQuark
Re: PIC I2C library problem
« Reply #5 on: January 23, 2014, 09:58:57 am »
Using not defined definitions  :-\

Offline alanbTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: gb
Re: PIC I2C library problem
« Reply #6 on: January 23, 2014, 10:01:36 am »
Using not defined definitions  :-\

Any Idea what the values for MASTER and SLEW_OFF should be?
 

Offline SPRX

  • Regular Contributor
  • *
  • Posts: 64
  • Country: au
Re: PIC I2C library problem
« Reply #7 on: January 23, 2014, 10:44:47 am »
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) – 1

If 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
« Last Edit: January 23, 2014, 11:23:14 am by SPRX »
 

Offline alanbTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: gb
Re: PIC I2C library problem
« Reply #8 on: January 23, 2014, 11:03:23 am »
Thank you SPRX I will try that when I return home this evening.
 

Offline SPRX

  • Regular Contributor
  • *
  • Posts: 64
  • Country: au
Re: PIC I2C library problem
« Reply #9 on: January 23, 2014, 11:10:20 am »
Actually, for the dsPIC30F4011 processor;

I2CBRG = (FCY/FSCL – FCY/1,111,111) – 1    (just referred to your processor datasheet) :)

and MASTER must be 0xFFFF
« Last Edit: January 23, 2014, 11:22:27 am by SPRX »
 

Offline Dreso12

  • Contributor
  • Posts: 17
Re: PIC I2C library problem
« Reply #10 on: January 23, 2014, 11:23:55 am »
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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC I2C library problem
« Reply #11 on: January 23, 2014, 12:02:40 pm »
Quote
What am I doing wrong?

The 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.
================================
https://dannyelectronics.wordpress.com/
 

Online Simon

  • Global Moderator
  • *****
  • Posts: 17884
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: PIC I2C library problem
« Reply #12 on: January 23, 2014, 05:22:36 pm »
Quote
What am I doing wrong?

The 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.

From 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 !
 

Offline diyaudio

  • Frequent Contributor
  • **
  • !
  • Posts: 683
  • Country: za
Re: PIC I2C library problem
« Reply #13 on: January 24, 2014, 09:07:57 pm »
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); generates
error: '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.

Try 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. 
 

Offline TooOldForThis

  • Regular Contributor
  • *
  • Posts: 57
  • Country: us
  • H: 42.576MHz/Tesla
Re: PIC I2C library problem
« Reply #14 on: January 25, 2014, 02:35:10 am »
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.
 

Offline manny87

  • Newbie
  • Posts: 3
Re: PIC I2C library problem
« Reply #15 on: January 27, 2014, 06:03:53 pm »
hi

I 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 name

you 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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf