Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: I2C communication |
Posted: Tue Dec 10, 2002 9:08 am |
|
|
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 |
|