PICmicro & dsPIC >> Source Share for PICmicro & dsPIC

Pages: 1
nono240



Reged: Feb 10 2005
Posts: 76
Loc: FRANCE
[PIC18] Interrupt-Driven I2C Routines (100% C Version)
      #18597 - Thu Aug 25 2005 05:12 PM Attachment (2718 downloads)

I've implemented the G.Neiss's code in 100% C for my 18F8722.

It's *ALMOST* the same except 16 bit device's address is not implemented since it was useless for me (but VERy easy to implement).

Don't forget the interrupt routine :

Code:
--------------------------------------------------------------------------------


//---------------------------------------------------------------------//
//-------------------------Low priority Interrupt----------------------//
//---------------------------------------------------------------------//
void interrupt low_priority lowISR()
{

//-------------Interrupt on I2C events----------------//
if(SSP1IF && SSP1IE)
I2Cmachine();

}

--------------------
In a world without walls nor Windows, who needs Gates ?


Post Extras: Print Post   Remind Me!   Notify Moderator  
G.Neiss

****

Reged: Dec 27 2004
Posts: 474
Loc: germany
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: nono240]
      #18600 - Thu Aug 25 2005 07:02 PM

It's a good 'reverse engeniering' of my assembler code

I would use it as a base point for implementing I2C on other processors.
Why ?
Look at the generated code and You will see, the assembler only version is faster.
But of course it's not portable.
So thanks for translating it.

ciao
Guenter


Post Extras: Print Post   Remind Me!   Notify Moderator  
nono240



Reged: Feb 10 2005
Posts: 76
Loc: FRANCE
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: G.Neiss]
      #18612 - Thu Aug 25 2005 11:11 PM

Quote:


It's a good 'reverse engeniering' of my assembler code







Quote:


Look at the generated code and You will see, the assembler only version is faster.





Sure ! Assembler is ALWAYS faster.
This version is for 'educational' purposes -> "I2C for newbies"

Quote:


But of course it's not portable.





Sure too...

Quote:


So thanks for translating it.




Thanks to you for your original code.

--------------------
In a world without walls nor Windows, who needs Gates ?


Post Extras: Print Post   Remind Me!   Notify Moderator  
2171984



Reged: Oct 15 2005
Posts: 1
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: nono240]
      #19351 - Sat Oct 15 2005 01:21 PM

thanks

Post Extras: Print Post   Remind Me!   Notify Moderator  
dimithri



Reged: Oct 16 2005
Posts: 1
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: 2171984]
      #19368 - Sun Oct 16 2005 06:25 PM

hello since we're on the topic I thought of asking this...

I'm having trouble with a project i've undertaken recently where i am trying to interface a Anybus module to a PIC18f452. Everything was going fine until i found that I don't have enough I/O pins to address the Anybus module's 12bit address. Therefore I wanted to use a PCF8575 I/O expander chip which uses I2C interface. But I'm already using the pins SCL and SDA pins for the DAC which I use (its interfaced using the SPI interface) hence I've got a problem. I'm already using PORTD an PORTE for the Parallel Slave Port (PSP) to get data to the Anybus and PORTA is used for the Analog to Digital converter and I only have PORTB (8bits) left. I've tried to implement a latching system where i address the 12bits with 8bits by de-multiplexing but its very complex. I'm using the PIC18f452 chip as stated before with MICRO CHIP MPLAB C18 compiler.

Hope somebody can help..
Thanks,
regards, Dimithri


Post Extras: Print Post   Remind Me!   Notify Moderator  
Dan HenryModerator
Guru
****

Reged: Oct 16 2003
Posts: 4622
Loc: Colorado
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: dimithri]
      #19375 - Mon Oct 17 2005 01:20 AM

A few ideas:
  • Have SPI and I2C devices share the MSSP pins. Although I have never tried it, apparently some have done it. For example, see Mixing I2C and SPI on the same pins.
  • Implement I2C in software on available GPIO pins (i.e., bitbang).
  • Move your DAC's SPI interface to available GPIO pins in implement SPI in software (i.e., bitbang), since bitbanging SPI is (arguably) easier than bitbanging I2C, and put the I/O expander on the MSSP's hardware I2C pins and switch the MSSP to I2C mode.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bolt

***

Reged: Oct 29 2003
Posts: 48
Loc: The Netherlands
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: Dan Henry]
      #21527 - Wed Mar 01 2006 09:21 PM

Change the DAC to an I2C version?... Use the I/O expander and the DAC on the I2C bus...

--------------------
Marko


Post Extras: Print Post   Remind Me!   Notify Moderator  
jlian168
stranger


Reged: Mar 31 2009
Posts: 1
Re: [PIC18] Interrupt-Driven I2C Routines (100% C Version) [Re: nono240]
      #104312 - Tue Mar 31 2009 06:35 PM

Deal sir:
Pardon me,My english not well.
I've a question for you?
I use the the I2C interrupt routine in PIC16F877A & DS1307,
But not stable,Because some time is good and sometime is bad!I don't know why?
//
1.DS1307 no connect Battery.
2.use SDA RC4 & SCL RC3(all pull-high)
3.MPLAB V8.10
4.PICC16 V9.6 std
5.cpu XTAL=4MHz
6.DS1307 xtal=32.768kHz
//
Could you help me?
Thanks you very much.
Have a nice day.
/*************************************************/
2009/04/02:
Now i think it may be no ack by battery no connect!
Because i connect the battery is running good.
/*************************************************/


Edited by jlian168 (Thu Apr 02 2009 02:01 PM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 5 anonymous users are browsing this forum.

Moderator:  jtemples, Dan Henry, Andrew L, mikerj 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 30013

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5