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

i2c Question

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



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

i2c Question
PostPosted: Thu Jun 17, 2004 1:18 pm     Reply with quote

Hi guys:

some days ago I asked a question but nobody post any answer. Ok, I will do the question in another way, without any code example of my program.

I need to communicate 2 PIC's ( a pair of 16F88 with internal oscillator at 8 MHz ) with i2c protocol. The Slave mut be implemented by interrupt because its work is to generate 2 PWM's by software at high freq. Those days I've been search through the forum and I've been studying the codes and the protocol itself too.

I've implemented some codes but I haven't got luck. The only way to make the slave work it to use the i2c built in functions by software and put and aditional pin to do an interrupt ( IOC, Interrupt On Change ) on of the pins RB4 to RB7 and wait for incomming data. Something like the SPI Chip Slect pin ....

Anybody has implemented a project with this pic in slave mode that works ? ( I don't need any code, only the certain that is possible to do that ).

All the proves I'd done determines that i2c in slave mode with interrupt doesn't works or I've missing something important.

Please, can all the "experts" put their ideas or solutions ( I'm including the CCS Programmers) ? ( There is a lot of people with trhe same problem ).

Thanx in advanz.

Joan.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Jun 17, 2004 4:20 pm     Reply with quote

IMHO the only way to get this working is to not use interupts or hand write them. Software PWM is not a resource hog at all. You can easily do software PWM while monitoring the I2C registers. For example;
Code:
Main
{  While(1)
   {   while(timer_Interupt_Flag)
       {  timer_Interupt_Flag=0;
          Service_PWM1;
          Service_PWM2;
       }
       Service_I2c;
   }
}


There is only one key to pulling this off. The loop time must be very fast. You can not use delays to perform the PWM. It can be done using a time base from a free running timer that will interupt on time reguardless of other task. This is the aproach I would take assuming the I2C port will be comunicating non-stop. The time it takes to service both PWM is probably less than it takes to jump into and out of an interupt.
davidpk



Joined: 29 Apr 2004
Posts: 13
Location: Opelika, AL

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Jun 17, 2004 4:21 pm     Reply with quote

Joan,

I haven't ever used the I2C slave mode but the CCS manual says you must use the hardware for slave mode. (See the #use i2c in the pre-processor section)

Does this help?

David
falleaf



Joined: 23 May 2004
Posts: 48

View user's profile Send private message

PostPosted: Fri Jun 18, 2004 10:41 am     Reply with quote

A friend shared his examples to me, and I'm using it. I see it no problem, but I'm trying to understand how the C work.

That is, it seems to many I2C ASM examples, but so clear. See in thread "Need I2C examples"

I also posted a simple example there.
Joan



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

PostPosted: Fri Jun 18, 2004 11:44 am     Reply with quote

Hi guys:

Neutone
----------

Efectively I'm using a free delay running for the PWM's ( a "for" routine for each one, not timer0 interrupt that perhaps is a more elegant solution ) , they works well ( 600 Hz ) with a resolution of 1% ... it's enougth to drive 2 toys motors. But PWM are not the problem. I'd calculated the delay for reading the i2c incoming data and I only loose 2 cicles of PWM in all the process of interrupt routine. And I can see it with an oscilloscope.

David
--------

Yes, I used the statement

#use I2C(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0xa0, SLOW, FORCE_HW)

But as I said in my previous message it's impossible to run it in this way.

falleaf
-------

I've seen lots of examples on the forum, revised the i2c protocol for the PDF file from PHILIPS and used all resources in the 16F88 that I can use for this pourpose, but I only can do it work in the way I said ( with IOC interrupt with an aditional pin and software i2c ).

I use the 16F88 not the 16F877 that you used. The main problem it that the PIC don't entry in the #int_SSP routine.

So, Neutone, David & falleaf, thanks for your posts.

The question: It is possible to run a 16F88 with internal oscillator at 8 MHz and Hardware i2c resources in slave mode ?

Regards.

Joan
falleaf



Joined: 23 May 2004
Posts: 48

View user's profile Send private message

PostPosted: Sat Jun 19, 2004 2:59 am     Reply with quote

I don't know muchie about C for PIC and don't know muchie bout 16F88. My old version of CCS C didn't support for 16F88 so I don't know.

However, if you only need to use, you can come to Nigel's tutorial and get the ASM code. It's very easy to use, just copy and paste. It's included the tutorial for software Slave mode.

In slave mode, you should use RB0 and any other pin as I2C port.

I used his code and used with 16F84A Smile) no need SSP hardware.

If you need to understand, I'm newbie in C for pIC Smile
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