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 support@ccsinfo.com

I2C communication

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







I2C communication
PostPosted: Tue Dec 10, 2002 3:42 am     Reply with quote

<font face="Courier New" size=-1>I have set I2c by Slave mode for Reception and Master mode for Transmission in PIC16F87x.
Master mode Transmission is ok!
When communication is in slave mode reception,
I see a interrupt in Star and one for stop.

But Address and Data is no detect.
Why???

NB. Address destination is = SSPADD.


void Init(void)
{
// Port B
PORTB = 0xFF;
TRISB = 0xF1;

// Port C
PORTC = 0xF9;
TRISC = 0xF8;

PORTD = 0xFF;
TRISD = 0x00;

OPTION = 0x83;


// Interrupt
// Inizializzo a 0 il registro INTCON (pag. 20 manuale)
INTCON = 0x00;
// Inizializzo a 0 il registro PIE1 (pag. 21 manuale)
PIE1 = 0x00;
// Inizializzo a 0 il registro PIR1 (pag. 22 manuale)
PIR1 = 0x00;
// Inizializzo a 0 il registro PIE2 (pag. 23 manuale)
PIE2 = 0x00;
// Inizializzo a 0 il registro PIR2 (pag. 24 manuale)
PIR2 = 0x00;

// Inizializzo I2C
i2c_InitSlaveMode();



// TIMER 0
TMR0 = 131;

// Cancello il pending bit di overflow del timer
T0IF = 0;

// Abilito l'interrupt di overflow del timer TMR0
T0IE = 1;

RCIE = 1; // Abilito l'interrupt sulla ricezione di un byte


// Abilito l'interrupt delle periferiche non mascherate
PEIE = 1;
// Abilito l'interrupt generale
GIE = 1;
}


void i2c_InitMasterMode(void)
{
SSPIE = 0; // Disabilito l'interrupt MSSP
SSPEN = 0; // Disabilito l'MSSP

ucFlagMode = TRANSMISSION;

SSPMode(MASTER_MODE); // set I2C Master Mode
SSPADD = ClockValue; // bite rate a 400kHz

STAT_CKE = 0; // use I2C levels
STAT_SMP = 1; // disable slew rate control

SSPIF = 0; // A zero l'interrupt SSPIF
BCLIE = 0; // A zero l'interrupt di bus collision

SDA_DIR = I2C_OUTPUT; // set output SCL e SDA
SCL_DIR = I2C_OUTPUT;

SSPEN = 1; // Abilito l'MSSP
SSPIE = 1; // Abilito l'interrupt MSSP
}

void i2c_InitSlaveMode(void)
{
SSPIE = 0; // Disabilito l'interrupt MSSP
SSPEN = 0; // Disabilito l'MSSP

SDA_DIR = I2C_INPUT;
SCL_DIR = I2C_INPUT;

ucFlagMode = RECEPTION;

// Bit 76543210
SSPSTAT = 0b10000000; //0b11000000
SSPCON = 0b00111110;
SSPCON2 = 0b10000000; //0b10000001
SSPADD = ucMyAddrI2c; // Inizializzo con il mio indirizzo

SSPIF = 0;

SSPEN = 1; // Abilito l'MSSP
SSPIE = 1; // Abilito l'interrupt MSSP

}
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 9927
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: I2C communication
PostPosted: Tue Dec 10, 2002 9:08 am     Reply with quote

If you get an interrupt for the Start and Stop but not the address or data, it sounds like the slave address does not match the address of the data being transmitted or the transmision of the data is not correct.

Regards,
Mark

:=<font face="Courier New" size=-1>I have set I2c by Slave mode for Reception and Master mode for Transmission in PIC16F87x.
:=Master mode Transmission is ok!
:=When communication is in slave mode reception,
:=I see a interrupt in Star and one for stop.
:=
:=But Address and Data is no detect.
:=Why???
:=
:=NB. Address destination is = SSPADD.
:=
:=
:=void Init(void)
:={
:= // Port B
:= PORTB = 0xFF;
:= TRISB = 0xF1;
:=
:= // Port C
:= PORTC = 0xF9;
:= TRISC = 0xF8;
:=
:= PORTD = 0xFF;
:= TRISD = 0x00;
:=
:= OPTION = 0x83;
:=
:=
:= // Interrupt
:= // Inizializzo a 0 il registro INTCON (pag. 20 manuale)
:= INTCON = 0x00;
:= // Inizializzo a 0 il registro PIE1 (pag. 21 manuale)
:= PIE1 = 0x00;
:= // Inizializzo a 0 il registro PIR1 (pag. 22 manuale)
:= PIR1 = 0x00;
:= // Inizializzo a 0 il registro PIE2 (pag. 23 manuale)
:= PIE2 = 0x00;
:= // Inizializzo a 0 il registro PIR2 (pag. 24 manuale)
:= PIR2 = 0x00;
:=
:= // Inizializzo I2C
:= i2c_InitSlaveMode();
:=
:=
:=
:= // TIMER 0
:= TMR0 = 131;
:=
:= // Cancello il pending bit di overflow del timer
:= T0IF = 0;
:=
:= // Abilito l'interrupt di overflow del timer TMR0
:= T0IE = 1;
:=
:= RCIE = 1; // Abilito l'interrupt sulla ricezione di un byte
:=
:=
:= // Abilito l'interrupt delle periferiche non mascherate
:= PEIE = 1;
:= // Abilito l'interrupt generale
:= GIE = 1;
:=}
:=
:=
:=void i2c_InitMasterMode(void)
:={
:= SSPIE = 0; // Disabilito l'interrupt MSSP
:= SSPEN = 0; // Disabilito l'MSSP
:=
:= ucFlagMode = TRANSMISSION;
:=
:= SSPMode(MASTER_MODE); // set I2C Master Mode
:= SSPADD = ClockValue; // bite rate a 400kHz
:=
:= STAT_CKE = 0; // use I2C levels
:= STAT_SMP = 1; // disable slew rate control
:=
:= SSPIF = 0; // A zero l'interrupt SSPIF
:= BCLIE = 0; // A zero l'interrupt di bus collision
:=
:= SDA_DIR = I2C_OUTPUT; // set output SCL e SDA
:= SCL_DIR = I2C_OUTPUT;
:=
:= SSPEN = 1; // Abilito l'MSSP
:= SSPIE = 1; // Abilito l'interrupt MSSP
:=}
:=
:=void i2c_InitSlaveMode(void)
:={
:= SSPIE = 0; // Disabilito l'interrupt MSSP
:= SSPEN = 0; // Disabilito l'MSSP
:=
:= SDA_DIR = I2C_INPUT;
:= SCL_DIR = I2C_INPUT;
:=
:= ucFlagMode = RECEPTION;
:=
:= // Bit 76543210
:= SSPSTAT = 0b10000000; //0b11000000
:= SSPCON = 0b00111110;
:= SSPCON2 = 0b10000000; //0b10000001
:= SSPADD = ucMyAddrI2c; // Inizializzo con il mio indirizzo
:=
:= SSPIF = 0;
:=
:= SSPEN = 1; // Abilito l'MSSP
:= SSPIE = 1; // Abilito l'interrupt MSSP
:=
:=}
:=</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 9934
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