Continue to Site

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.

I2C using 16f877a (datas from slave to master)

Status
Not open for further replies.

gopintj

Member level 4
Joined
Sep 1, 2010
Messages
77
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
Thirukalukalukundra, Kanchipuram, Tamilnadu, India
Activity points
1,953
Hi, I would like to write a program to get data from a slave. for that, i would like to know how to configure the program inorder to get data from slave. Please provide me a simple source code which helps me to learn quickly.

I am using high tech c compiler and my micro controller is 16f877a.
 

Hi, I am getting some unknown error that, i cannot get data from SLAVE. I used PCF8574A to get parallel data from slave and tried to send them to PIC master.
I used this following procedure to send serial data.
Let it be P0,P1,P2,..P7
i wrote a program that,

I, first initialized the address of the I/O expander.

i2c_write(0x70); //address of the slave.
SSPBUF=i2c_read(); //Getting Data from Slave and coping it to SSPBUF.
j=SSPBUF; //J is initiated at the top of the program.


Then, i included an another function which is used to check the value of SSPBUF.
So that, if the input data is greater than 0xB0 (0d175) then the IF condition gets executed and turning RB7 from 0 to 1. I have connected an LED to RB7 so that to check whether RB7 turns ON if my input data is above 176.

This is that sub function.

void check(unsigned int c)
{
if(c>=0xB0)
{
RB7=1;
DelayMs(100);
}
else
{
RB7=0;
DelayMs(100);
}
}

After doing this software works, i then jumped into PROTEUS in order to give the circuit connections.
I have given all the circuit connections correctly for PIC16f877a and then i gave connections to PCF8574A which is shown in the below diagram.

In order to provide the value of 0xB0 or 0d176, i just connected the pins P0,P1,P2,P3 and P6 to ground and P4,P5 and P7 as +5v

But, the LED glows even though if i didn't press the push button which is shown in the below diagram. asdf.JPG
 

The PCF8574A's GPIO have unusual characteristics and are classified as Quasi Bidirectional:

Referenece AN469 - I2C/SMBus general purpose I/O expanders datasheet, pg. 4, Section 2.1 Quasi bi-directional GPIOs



Quasi bi-directional GPIO devices have the following common features:

• I/O structure: quasi-bi-directional I/O port with an internal weak current-source pull-up.
This architecture allows a good sink current capability (25 mA) but a limited source
current capability (100 μA). This simple I/O structure allows the use of the I/O as input
or output without the need of an internal configuration register. See Section 3 “Quasi
bi-directional GPIO programming” for more details.

• I/O current drive capability:
– sink capability = 25 mA
– source capability = 100 μA

• Power-up state: devices power up with I/Os configured as inputs.

You should design your circuit accordingly.

BigDog
 
  • Like
Reactions: FvM

    FvM

    Points: 2
    Helpful Answer Positive Rating
Is it necessary for both MASTER(PIC) and SLAVE(PIC) to have I2C protocol in case of data transmission from slave to master?

If I understand your question correctly.

It is necessary for both the Master and Slave to have implemented I2C, if you intend on using an I2C bus to communicate between the two PICs.

Does this answer your question?

BigDog
 
  • Like
Reactions: FvM and gopintj

    gopintj

    Points: 2
    Helpful Answer Positive Rating

    FvM

    Points: 2
    Helpful Answer Positive Rating
yes, i got the answer. Thank you.
This project is about getting temperature from multiple slaves say 10 or more in numbers. For that, i have written a c program using MP LAB IDE with Hi tech C compiler. This program contains the details and steps of calling each and every slave using their address.

Now i got that, both the transmitter and receiver must be synchronized by an I2C bus.

I am trying to use DS18b20 as a temperature sensor. but i m suffering that, DS18b20 is a 16-bit temperature sensor and my pic is an 8-bit micro controller.

Do you know any other temperature sensor which has the data in 8-bit.?
 

I've used the DS18S20 quite extensively in various projects:

**broken link removed**

It still uses two bytes of data to represent the temperature value, however the MSB is entirely sign bits.

**broken link removed**

Other than that is basically the same device.

By the way, both devices have a unique 64-bit address, so you can attach more than one device to the same I2C bus.

BigDog
 
  • Like
Reactions: FvM and gopintj

    gopintj

    Points: 2
    Helpful Answer Positive Rating

    FvM

    Points: 2
    Helpful Answer Positive Rating
I would like to transmit and receive data between two 16f877a in which one as Master and One as slave.
In this, i have two doubts.

1. Can i connect the SDA and SCL pins of master directly to SDA and SCL pins of Slave without using an I2C expander?

2. If i connect SDA and SCL of master and slave, i need to give address of slave. How can i give a address to 16f877a?
Please guide me.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top