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 support@ccsinfo.com

i2c_write() is not allowed

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



Joined: 05 Jan 2019
Posts: 5

View user's profile Send private message

i2c_write() is not allowed
PostPosted: Sat Jan 05, 2019 11:12 am     Reply with quote

Trying to get htis up for hte first time.

When I try to compile with i2c included I get
Function used but not defined: :: i2c_start() not supported when using HW I2C on this device, see i2c_transfer()

Setup is
Code:

#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8,stream=PORT1)
#pin_select SDA1=PIN_C4
#pin_select SCL1=PIN_C3
#use i2c(Master,slow=100000, I2C1)

#define LED PIN_D7
#define DELAY 10

I can read and write to the device on uart.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 11:46 am     Reply with quote

What chip?.

Vital data.
mire



Joined: 05 Jan 2019
Posts: 5

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 12:18 pm     Reply with quote

PIC18F45K42.

Can use the I2C HW ok from MPLab.

Found that using
#use i2c(Master,slow=100000)
and the code compiles and downloads.
But it does nothing on the port (see with oscilloscope).
_________________
: In the
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 12:34 pm     Reply with quote

OK. Your chip does not have the MSSP. Instead it has a dedicated I2C
module. This supports multi-byte buffered I2C, and can automatically
generate a start when data is sent. This is why CCS are suggesting
to use the I2C_transfer function. This can automatically do the entire
transfer.
I must admit I would have expected the older mode to still be supported
Will have a play when I get back to my development system.
Why not just use I2C_transfer?.
mire



Joined: 05 Jan 2019
Posts: 5

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 1:13 pm     Reply with quote

By all means have a play.
But if it won't work I'll figure it out.
Really was more interested in seeing CCS working.
Do you know if CCS supports a Dallas style 1 wire interface?

Regards.
_________________
: In the
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 1:25 pm     Reply with quote

mire wrote:

Really was more interested in seeing CCS working.

If you just want to look at the bus and see if it's active, then try this:
Code:

#include <18F45K42.h>
#fuses NOWDT
#use delay(internal=4M)

#pin_select SDA1=PIN_C4
#pin_select SCL1=PIN_C3
#use i2c(Master,slow=100000, I2C1)

//======================================
void main()
{                                                                     
int8 my_data = 0x55;

while(TRUE)
  {
   i2c_transfer(0xA0, &my_data, 1);
   delay_us(100);
  }

}
temtronic



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

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 1:59 pm     Reply with quote

I don't know if CCS has a driver in their library but there are several postings of 'one wire' code in the code library and I've used DS18B20 temp sensors with PICs for years.
'drivers' can be quite a challenge. Often you need to make them 'generic', applicable to several PICs or 1-wire devices and not everyone needs every function of every device connected to every PIC.
In my case I 'cheated', only used enough code to read the sensor as I didn't need anything else. I also 'cheated' by using 1 I/O pin per device ( 4 in total). While that made the code larger, no need to read device IDs, etc. PICs have LOTS of codespace these days. Also by having 1 device per pin a failure in one wire doesn't kill the rest of them, though I have a way around that...

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Jan 05, 2019 3:04 pm     Reply with quote

There are several one wire device drivers in the CCS code.

DS18B20 (thermometer).
DHT11 (humidity).
DS2432 (EEPROM).

There may well be more. As Jay has said there are also drivers in the
code library.

Looking at the code being generated for I2C, the reason they are not supporting I2C start is that they are setting the peripheral up to support
the automatic generation of start, when data is loaded. So targeted at
using the I2C_transfer format. If you must use start separately it is only
a matter of defining a couple of bits to change the mode, and then just
setting the control bit for this manually.
mire



Joined: 05 Jan 2019
Posts: 5

View user's profile Send private message

PostPosted: Sun Jan 06, 2019 7:27 am     Reply with quote

Thanks all.
Understood.
However if I 'FORCE_SW' should I see a Bit Bash version?
Still no output

thanks
(How do you close a thread)
_________________
: In the
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 06, 2019 8:24 am     Reply with quote

from my foggy memory..

FORCE_SW will create a bit bashed driver, for any 2 I/O pins, providing they
are bidirectional, however you will not get interrupt capability.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 06, 2019 11:10 am     Reply with quote

mire wrote:

However if I 'FORCE_SW' should I see a Bit Bash version?
Still no output

Do you have pull-up resistors on the bus ? Those are necessary to
see signal activity.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Jan 06, 2019 11:43 am     Reply with quote

Also have you turned off analog I/O. This has priority over digital.
mire



Joined: 05 Jan 2019
Posts: 5

View user's profile Send private message

PostPosted: Thu Jan 10, 2019 6:24 pm     Reply with quote

Where do I find the code for the DHT11 say.
_________________
: In the
temtronic



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

View user's profile Send private message

PostPosted: Thu Jan 10, 2019 6:30 pm     Reply with quote

CCS puts the drivers for devices like the DHT11 in the 'drivers' folder.
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