CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SOLVED: i2c_speed - unable to resolve identifier i2c_speed

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

SOLVED: i2c_speed - unable to resolve identifier i2c_speed
PostPosted: Mon Mar 21, 2016 5:32 am     Reply with quote

Hi,
I found i2c_speed in the ccs c manual, but the compiler gives "unable to resolve identifier i2c_speed".
Note the other functions i2c_start, i2c_write, i2c_read, and i2c_stop work fine.
I use a PIC18F67K90 @ 20MHz.

I have used:
#use i2c
Code:

    i2c_speed(400000);   // unable to resolve identifier i2c_speed
   
    i2c_start();
    i2c_write(MCP7940_ADDRESS);
    i2c_write(address);

Why is the function not known?

Regards,
Jack.


Last edited by JackB on Thu Mar 24, 2016 5:45 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9255
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 5:57 am     Reply with quote

might be a compiler version bug ?
which compiler do you have ?
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 6:07 am     Reply with quote

Thanks for the quick response!
I also have: Option invalid - Bad Option: #use i2c
In the lst file I found:
CCS PCH C Compiler, Version 5.055, 29447
I'm using it with MPLAB X on a Linux Mint laptop.
temtronic



Joined: 01 Jul 2010
Posts: 9255
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 6:13 am     Reply with quote

did a real quick check...
i2c_speed(xxx);
ONLY works for the HARDWARE I2C module according to the manual (F11)
it should be available for all PICs with HW I2C.

reply with full #use i2c(....)
that error says 'something' in (......) is wrong, not allowed, typo, etc.)

Jay
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 7:16 am     Reply with quote

Thanks,
now I use:
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4)
It still doesn't know this function
i2c_speed(400000);
But I guess, I addressed that with "FAST"?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 7:39 am     Reply with quote

JackB wrote:
now I use:
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4)
It still doesn't know this function

Read the CCS manual in the #use i2c section. It says:
Quote:

#use i2c( )

Software functions are generated unless FORCE_HW is specified.


Then read the manual in the i2c_speed() section. It says:
Quote:
i2c_speed( )

This only works if the hardware I2C module is being used.

You are using software i2c. That's why you get the error.
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 7:55 am     Reply with quote

I use FORCE_HW, it still gives a warning for the i2c_speed function, but it compiles.
However, the software starts to hang after the first i2c_write(MCP4726_ADDRESS); function.
Ttelmah



Joined: 11 Mar 2010
Posts: 19568

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 8:19 am     Reply with quote

Several comments:

1) It is much easier and safer, to just specify the I2C port to use:

#use i2c(MASTER, FAST, I2C1)

is equivalent to:

#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)

and means you can't get the pin numbers wrong. On later chips with relocatable peripherals, you have to use this syntax, so it is worth always using it when you want the hardware.

2) Why not just specify the speed in the use statement?:

#use i2c(MASTER, FAST=400000, I2C1)

3) The most likely reason for it hanging, is that some feature of the bus prevents 400K from working:
A device too slow for this.
Pull up resistors too large.
Too much capacitance on the bus.

The second and third link to one another, and to what voltage you are using to drive the bus.
Do you have any other devices on the I2C bus?.
What pull-up values are you using?.
How long is the connection, what sort of wire?.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 8:41 am     Reply with quote

JackB wrote:
I use FORCE_HW, it still gives a warning for the i2c_speed function

You said in another thread that this is your version:
Quote:
CCS PCH C Compiler, Version 5.055.


You didn't provide a test program so I made one, as shown below.
I compiled it with vs. 5.055 and there are no errors at all:
Code:
Executing: "C:\Program files\Picc\CCSC.exe" +FH "PCH_Test.c" +DF +LY  -T -A +M -Z +Y=9 +EA #__18F67K90=TRUE
      Memory usage:   ROM=0%      RAM=0% - 0%
      0 Errors,  0 Warnings.
Build Successful.
Loaded C:\Program Files\PICC\Projects\PCH_Test\PCH_Test.cof.
BUILD SUCCEEDED: Mon Mar 21 07:39:27 2016

Test program:
Code:
#include <18F67K90.H>   
#fuses HSH, NOWDT
#use delay(clock=20M)

#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)

#define MCP7940_ADDRESS 0xDE

//=====================================
void main()
{
int8 address = 0x00;

i2c_speed(400000);   
   
i2c_start();
i2c_write(MCP7940_ADDRESS);
i2c_write(address);

while(TRUE);
}
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 12:51 pm     Reply with quote

Hi,

yes, my compiler version is indeed still the same.
I use 5k pull-up resistors.
I use the LM75B, MCP7940N, MCP4726, all support 400KHz speed.

One of those hangs with i2c_write:
#use i2c(MASTER, FAST=400000, I2C1) and
#use i2c(MASTER, FAST, I2C1)

This works fine:
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4)

Regards,
Jack.
Ttelmah



Joined: 11 Mar 2010
Posts: 19568

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 2:05 pm     Reply with quote

If you have four devices on the bus, 5K is much too large. Each device adds capacitance.
The version that works, is using software I2C. This changes two things. First software is unlikely to get to 400K. You ask for 400K, but using the software routines, at 20MHz, you will probably only get to perhaps around 250K. The second thing it changes is the voltage the PIC sees as Vih. The I2C uses I2C transceivers that require the voltage to get to 0.8*Vdd, the software instead uses the port transceivers that have a lower Vih.
You will not be meeting the required I2C transition times on the rising edges, using 5KR.
You have also not answered about the actual length of the bus.

Try 1K5, which is safely above the value allowed by the I2C current limit.
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 3:34 pm     Reply with quote

Hi Ttelmah,
Thank you very much!
What you explain to me, makes much sense.
The total physical length of the tracks on the PCB may be 10cm at maximum.
Regards,
Jack.
JackB



Joined: 04 Mar 2016
Posts: 32
Location: Netherlands

View user's profile Send private message

PostPosted: Thu Mar 24, 2016 5:44 am     Reply with quote

Hi, I changed the pull-up resistors from 4k7 to 1k5.
It did not help, but I still think that is better.

This hangs i2c_write:
#use i2c(MASTER, FAST, I2C1)

And this works, it might be software i2c, though.
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4)

Thank you all for your help!
I think I don't bother this for now.
Although, with the help of all of you friends, I hoped to help other people who needed to use software i2c because hardware i2c doesn't work!

Regards,
Jack.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group