Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CCS-IDE wizard for I2C code

Status
Not open for further replies.

tom_hanks

Full Member level 5
Joined
Aug 28, 2003
Messages
243
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Activity points
1,578
i2c ccs

Hi,
Does any one is using CCS-IDE for PIC programming.....

I have written a code for I2C, but it is not giving the required result...

i was thining to see the code generated from CCS-IDE wizard....

if any one can generate the code for PIC16F818, then it would be helpfull for me for refrence...
 

CMOS

Advanced Member level 3
Joined
Jan 6, 2004
Messages
864
Helped
94
Reputation
186
Reaction score
50
Trophy points
1,308
Location
USA
Activity points
5,673
ccs i2c

Check out the examples folder of CCS. It has large number of I2C codes for 24Cxx EEPROM and other peripherals.
 

tom_hanks

Full Member level 5
Joined
Aug 28, 2003
Messages
243
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Activity points
1,578
ccs i2c slave

dear cmos,

thank you...
i have already ckech those file...but they are not helpfull...
 

kender

Advanced Member level 4
Joined
Jun 19, 2005
Messages
1,422
Helped
138
Reputation
276
Reaction score
38
Trophy points
1,328
Location
Stanford, SF Bay Peninsula, California, Earth, Sol
Activity points
9,970
ccs #use i2c

Here's what CCS project wizard had generated for my PIC18LF4220:
Code:
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

What results do you require from your code and what are you actually getting?
 

tom_hanks

Full Member level 5
Joined
Aug 28, 2003
Messages
243
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Activity points
1,578
ccs ide

I am using a PIC as a I2C bridge...

for slave, i am using hardware and for master I am using software I2c..
software one is working fine....
while the hardware I2C is not working properly...
this is the code for HW..
once master accumlates the data, it will store and pass it to slave hw interface...

//===================
#INT_SSP
void i2c_interrupt_handler(void) // Interrupt handler for slave I2C
{
#use i2c(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0x60, FORCE_HW)
BYTE state;
state = i2c_isr_state();

if(state == 0x80) // Master is requesting data
{
for (i=0;i<4;++i)
{
i2c_write(ADC_store); // Low byte of command
i2c_write(ADC_store>>8); // High byte of command
}
}
else if(state < 0x80) // Master is sending data
{
recvx = i2c_read();
ADC_store[1] = recvx;
}
}
 

kender

Advanced Member level 4
Joined
Jun 19, 2005
Messages
1,422
Helped
138
Reputation
276
Reaction score
38
Trophy points
1,328
Location
Stanford, SF Bay Peninsula, California, Earth, Sol
Activity points
9,970
ccs i2c examples

I've never had a PIC that would work as both master and slave on 2 different I2C buses. Even if CCS compiler can't handle multiple #use i2c(...) directives, you can write your own bit-banged software I2C code for the bus, where PIC is a master, and use only one #use i2c(..., slave) for the bus, where the PIC is a slave.

I would recommend the specialized CCS forum (if you don't know about it already) https://www.ccsinfo.com/forum . I vaguely recall that a situation similar to yours have been discussed there, so you might be able to simply find the existing threads. There are lots of I2C bit-banging codes too.
 

are

Advanced Member level 4
Joined
Nov 16, 2004
Messages
111
Helped
17
Reputation
34
Reaction score
12
Trophy points
1,298
Location
Balen (Belgie)
Activity points
644
i2c interrupt ccs

Look at the CCS help, you will find The SLAVE mode should only be used with the build-in SSP. This means :
#use I2C(slave,sda=PIN_C4,scl=PIN_C3 address=0x60,FORCE_HW)

You can only use PIN_C4 and PIN_C3 not the B1,B4
 

kender

Advanced Member level 4
Joined
Jun 19, 2005
Messages
1,422
Helped
138
Reputation
276
Reaction score
38
Trophy points
1,328
Location
Stanford, SF Bay Peninsula, California, Earth, Sol
Activity points
9,970
i2c_isr_state

are said:
Look at the CCS help, you will find The SLAVE mode should only be used with the build-in SSP. This means :
#use I2C(slave,sda=PIN_C4,scl=PIN_C3 address=0x60,FORCE_HW)

You can only use PIN_C4 and PIN_C3 not the B1,B4

One more thing in your code seems peculiar: you switch into a slave mode inside a slave interrupt. That's a catch-22.
 

tom_hanks

Full Member level 5
Joined
Aug 28, 2003
Messages
243
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Activity points
1,578
i2c ccs slave

yes, i got the help from the CCs Forum..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top