![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi,
i want to use DS1307(RTC) and DS1820(Temprature Sensor) in my project. my micro is 16F877A and compiler is MikroC. this micro has one I2C bus but i have 2 I2C device. can i use this 2 device in my project? |
|
|
|
|
|
|
(permalink) |
|
You can use quite a few devices on the same I2C bus as long as they have different addresses.
But the DS18S20 is not an I2C device, it's a 1-wire device and not I2C bus compatible. |
|
|
|
|
|
|
(permalink) |
|
Thank you blueroomelectronics,
you are right. |
|
|
|
|
|
|
(permalink) |
|
If it wasn't a one-wire and you still wanted 2 I2C controls you could also do so by using the mikroC Soft_I2C library. This allows you to specify the SDA, SCL pins to be whatever you like. So you could have one using the default SDA/SCL pins RC4 and RC3 and then you could wire up two others as well e.g. RB4 and RB5.
Last edited by richacm; 17th June 2008 at 01:27 AM. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
Thank you very much.
i was worked with one I2C bus but i did not work with two I2C device. i have a question. when i assign one address on my bus, witch device take first address? |
|
|
|
|
|
|
(permalink) |
|
You don't 'assign addresses', each device has it's own address assigned when the chip is made - although many have external pins you can use to select one of a number of addresses. Eight pin EEPROM's are a prime example.
|
|
|
|
|
|
|
(permalink) |
|
thanks Nigel,
imagin that i want to use one DS1307. i use this code for writeing data: //---------------------------------------------------------------- void write_DS1307(unsigned short address, unsigned short data) { I2C_Start(); I2C_Wr(0xd0); I2C_Wr(address); I2C_Wr(data); I2C_Stop(); } //---------------------------------------------------------------- i wrote my own address in code. now, if i had two DS1307, how can i assign address? witch Device take first address? |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
|
|
(permalink) |
|
The DS1307 has a fixed I2C address of 0b1101000x (0xD0, 0xD1)
The Philips I2C guide should help. http://www.nxp.com/acrobat_download/.../AN10216_1.pdf |
|
|
|
|
|
|
(permalink) |
|
You can only have 1 DS1307 on the I²C bus as it doesn't have any address pins but why would you want two? You can put 8 serial EEPROMS, a DS1307, an MCP9800 temperature sensor, a battery monitor etc. on the same bus. Send the correct address and the device assigned that address will answer.
Mike. |
|
|
|
|
|
|
(permalink) |
|
Hi Heasm,
yes, you can use two I2C devices,but a little tricky. You must spend one pin of your controller. Use a digital switch like 74HC157. This has 4 switches with 2 inputs (A, B) and one output (Q) each. It can be triggered through Select A/B. It would be sufficient to switch the CLK only, but you have 4 switches, so you can switch CLK and Data Line of the I2C bus. Some remarks to your code example. You must first configure the MSSP as I2C operation. It ist done with the following code sequence, I call it ConfigI2C: void ConfigI2C(void) { INTCON2 = 0x80; // Disable port B pullups PIR1bits.SSPIF = 0; // Clear MSSP Interrupt Flag bit PIR2bits.BCLIF = 0; // Clear Bus Collision Interrupt Flag bit DDRBbits.RB1 = 1; // Configure SCL as input DDRBbits.RB0 = 1; // Configure SDA as input OpenI2C(MASTER, SLEW_OFF); SSPADD = I2C_BaudRate; // I2C transfer rate 100 kc } Don't forget the external pullups for RB0 and RB1. I use 4.7 kOhms for 100 kHz bus speed. Next I miss the IDLE calls in your example. This is a working routine. Reading one byte from the device. You can use it as a template. unsigned char PCF8574_inp(unsigned char subaddr) { unsigned char cw; StartI2C(); while(SSPCON2bits.SEN); WriteI2C(PCF8574_addr+subaddr*2+Read); IdleI2C(); cw = ReadI2C(); NotAckI2C(); while(SSPCON2bits.ACKEN); StopI2C(); while(SSPCON2bits.PEN); CloseI2C(); return(cw); } With greetings ERhard Last edited by ESchemainda; 17th June 2008 at 05:38 PM. |
|
|
|
|
|
|
(permalink) |
|
Sorry, I made an error.
The device for switching must be bi-directional. So one cannot use the 74HC157. I don't know whether a bidirectional device exists, so the circuit would become some difficult. May be it will work by only switching the CLK line, without clock stretching, but I'm not sure. Sorry again. Erhard |
|
|
|
|
|
|
(permalink) |
|
thank you so much . . . all
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
It would be possible to use an analog bidirectional gate, if it was required for selection.
__________________
Eric "Good enough is Perfect" PIC tutorials: Gramo's: www.digital-diy.net/ Bill's: www.blueroomelectronics.com/ |
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| 16f877A | watzmann | Micro Controllers | 1 | 9th April 2008 09:41 PM |
| Two VSS & Two VDD in PIC 16F877A. | Suraj143 | Micro Controllers | 15 | 22nd November 2007 08:22 AM |
| RTC with pic 16f877a | fernandoagf | General Electronics Chat | 1 | 14th October 2007 11:12 PM |
| pwm and 16F877A | williB | Micro Controllers | 15 | 12th September 2006 08:08 AM |
| 16F877A help | TKS | Micro Controllers | 9 | 17th March 2004 12:12 PM |