|
|
View previous topic :: View next topic |
Author |
Message |
Renato and Davide Guest
|
I2C |
Posted: Mon Nov 12, 2001 11:56 am |
|
|
We have written this code to do a master slave i2c comunication between two
pic16f877, but we have some problems:
*************MASTER*********
(in main, not interrupt)
#use I2C(master, sda=PIN_C4, scl=PIN_C3, SLOW, NOFORCE_SW)
void i2c_master()
{
i2c_start();
i2c_write(0x0E);
i2c_stop();
}
**************SLAVE************
#use I2C(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x0E, SLOW, NOFORCE_SW)
byte slave_address;
#INT_SSP
void i2c_slave()
{
if(i2c_poll()==TRUE) slave_address=i2c_read();
}
We've obviously enabled the SSP and the GLOBAL interrupts.
This is what happens:
1)The master sends the slave address and waits; the main of the master
results blocked.
2)The slave doesn't receive anything from the master therefore doesn't
perform any interrupt (neither answer to a simple poll() function).
3)Also if no interrupt call is performed in the slave, the i2c_poll()
function always returns FALSE, becouse the buffer SSPBUF is always empty
(the slave receive nothing).
5)We have seen that some important registers are not set (such as SSPCON).
6)The only register written by the slave is SSPADD register.
Questions:
1. Is it correct our code for I2C master and slave?
2. If not, where is the mistake?
3. We cannot see the assembly code of any pre-processor directive, also if
no #NOLIST directive is called. Why?
4. We think it's important to set the SSPCON(1 and 2) and SSPSTAT registers.
With the code written before these registers are not written. Is it correct?
5. If not how can we write them?
6. Are you sure that Start and Stop conditions cause an interrupt to the
slave?
IDE Version = 2.32
PCB Version = 3.043
PCM Version = 3.043
Thank you for the support. Best regards
___________________________
This message was ported from CCS's old forum
Original Post ID: 1070 |
|
|
Tomi Guest
|
Re: I2C |
Posted: Mon Nov 12, 2001 1:00 pm |
|
|
:=void i2c_master()
:={
:= i2c_start();
:= i2c_write(0x0E);
:= i2c_stop();
:=}
The address detection happens automatically.
You must send out at least one data byte.
Slave ISR activated for data transfer.
See "ex_slave.c" for more details.
___________________________
This message was ported from CCS's old forum
Original Post ID: 1072 |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
Re: I2C |
Posted: Tue Nov 13, 2001 12:30 pm |
|
|
Hello
:=3. We cannot see the assembly code of any pre-processor :=directive, also if #NOLIST directive is called. Why?
Because you use an 16f87x. They have build-in modules for I2C support. The compiler only generates inline code after a i2c c-function (not like software implementation).
mfg
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 1086 |
|
|
|
|
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
|