• AVR Freaks

Hot!TWo PIC 18f4620 , one as master & the second is slave I2C communication problem

Page: < 12345.. > >> Showing page 4 of 9
Author
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:19:09 (permalink)
0
 
Which mode/address are you now using for simulator and real hardware?


SSPM3:SSPM0: Master Synchronous Serial Port Mode Select bits(2)
1111 = I2C Slave mode, 10-bit address with Start and Stop bit interrupts enabled
1110 = I2C Slave mode, 7-bit address with Start and Stop bit interrupts enabled
1011 = I2C Firmware Controlled Master mode (Slave Idle)
1000 = I2C Master mode, clock = FOSC/(4 * (SSPADD + 1))
0111 = I2C Slave mode, 10-bit address
0110 = I2C Slave mode, 7-bit address
 
I use "0110" for the slave . "1000" for the master
#61
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:22:56 (permalink)
0
that is what i think the slave is not reacting to anything . As if i doesnt receive anything because if i am not mistaken if she receive wrong address or overflow or collision happens , "PIR1.SSPIF" should equal 1 and MSSP interrupt happens
#62
rodims
Super Member
  • Total Posts : 1478
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:32:13 (permalink)
+1 (1)
I did not mean SSPMx, which is correct.
I was talking about GCEN mode and your addresses used for master and slave.
In your last code excerpt the slave still used address 0 ...
#63
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:42:39 (permalink)
+1 (1)
I used this 0x00 Address & GCEN to check the problem of shifted or non-shifted address betwen the master and slave 
 
now i have this in master code

void main()
{
I2C_Master_Init(100000); //Initialize I2C Master with 100KHz clock
Delay_ms(500);
while(1)
{
I2C_Master_Start(); //Start condition
I2C_Master_Write(0x30);

 
and this in slave code
  I2C_Slave_Init(0x18); 

 

SSPSTAT = 0b10000000;
SSPADD = address;
SSPCON1 = 0x36;
SSPCON2 = 0b00000001;

#64
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:44:41 (permalink)
0
the problem is slave it acts as if it is not connected nor existed at all
 
#65
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:47:25 (permalink)
0
but for ur knowledge when i used "1110 = I2C Slave mode, 7-bit address with Start and Stop bit interrupts enabled" for the slave mode the interrupt happens and the LED lights up 
 
#66
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 06:52:42 (permalink)
0
LOOK https://imgur.com/OFqminZ  it just interrupt for any incoming start stop singal so the slave is not completly dead , i just dont know what is wrong with the mode of "SSPMx =0110"
 
#67
rodims
Super Member
  • Total Posts : 1478
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:02:34 (permalink)
+1 (1)
May be its time again to post your complete code for master and slave.
As you wrote in #27  http://www.microchip.com/forums/FindPost/1024385
you are using completely new code copied from somewhere.  It's not obvious what you have changed so far. You are using PIC18F2620, but the the source was for some different hardware.
// PIC16F877A Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
#include <pic16f877a.h>

 
You probably changed that, but why guess, what you have changed ...
#68
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:13:56 (permalink)
0
The complete code for master pic 18f4620

 
 
 
//MAster pic 18f4620
const unsigned short int crystalOscillator =4000000;
 
 
 
void I2C_Master_Init(const unsigned long c)
{
SSPCON1 = 0b00101000;
SSPCON2 = 0;
SSPADD = (crystalOscillator/(4*c))-1;
SSPSTAT = 0;
TRISC.B3 = 1; //Setting as input as given in datasheet
TRISC.B4 = 1; //Setting as input as given in datasheet
}
 
 
 
void I2C_Master_Wait()
{
while ((SSPSTAT & 0x04) || (SSPCON2 & 0x1F));
}
 
 
 
void I2C_Master_Start()
{
I2C_Master_Wait();
SSPCON2.SEN = 1;
}
 
 
 
void I2C_Master_RepeatedStart()
{
I2C_Master_Wait();
SSPCON2.RSEN = 1;
}
 
 
 
void I2C_Master_Stop()
{
I2C_Master_Wait();
SSPCON2.PEN = 1;
}
 
 
 
void I2C_Master_Write(unsigned short int d)
{
I2C_Master_Wait();
SSPBUF = d;
}
 
 
 
unsigned short int I2C_Master_Read(unsigned short int a)
{
unsigned short temp;
I2C_Master_Wait();
SSPCON2.RCEN = 1;
I2C_Master_Wait();
temp = SSPBUF;
I2C_Master_Wait();
if(a==1){SSPCON2.ACKDT=1;}
else{SSPCON2.ACKDT=0;}
SSPCON2.ACKEN = 1;
return temp;
}
 
 
 
void main()
{
I2C_Master_Init(100000); //Initialize I2C Master with 100KHz clock
Delay_ms(500);
while(1)
{
I2C_Master_Start(); //Start condition
I2C_Master_Write(0x30); //7 bit address + Write
// I2C_Master_Write(0x00); //Write data
//I2C_Master_Write(0x00);
I2C_Master_Stop(); //Stop condition
Delay_ms(2000);
}
}
 
 
 

 
post edited by ubuntuman - 2017/11/13 08:27:50
#69
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:15:01 (permalink)
0
The complete code for Slave pic 18f4620

 
 
 
 
 
//Slave pic 18f4620
 
//##############################################################################
unsigned short int zed=0;
volatile unsigned short int new =0 ,dataRead=0 , dataWrite=0;
unsigned char dataReadCh[7] , dataWriteCh[7];
//##############################################################################
void interrupt()
{
if(PIR1.SSPIF == 1)
{
SSPCON1.CKP = 0;
new=1;
if ((SSPCON1.SSPOV) || (SSPCON1.WCOL))
{
zed = SSPBUF; // Read the previous value to clear the buffer
SSPCON1.SSPOV = 0; // Clear the overflow flag
SSPCON1.WCOL = 0; // Clear the collision bit
SSPCON1.CKP = 1;
}
if((!SSPSTAT.D_A||SSPSTAT.D_A) && !SSPSTAT.R_W)
{
while(!SSPSTAT.BF){};
while(SSPSTAT.BF){dataRead = SSPBUF;}
SSPCON1.CKP = 1;
}
else if((!SSPSTAT.D_A||SSPSTAT.D_A) && SSPSTAT.R_W)
{
while(SSPSTAT.BF){zed = SSPBUF;}
SSPBUF = dataWrite ;
SSPCON1.CKP = 1;
while(SSPSTAT.BF){};
}
PIR1.SSPIF = 0;
}
}
//##############################################################################
void I2C_Slave_Init(unsigned short int address)
{
SSPSTAT = 0b10000000;
SSPADD = address;
SSPCON1 = 0b00110110;
SSPCON2 = 0b00000001;
TRISC.B3 = 1; //Setting as input as given in datasheet
TRISC.B4 = 1; //Setting as input as given in datasheet
TRISC.B0=1;
TRISC.B1=1;TRISC.B2=1;TRISC.B5=1;TRISC.B6=1;TRISC.B7=1;
INTCON = 0b00000000;
INTCON.PEIE = 1;
INTCON.GIE = 1;
PIE1.SSPIE = 1;
PIR1.SSPIF = 0;
while(SSPSTAT.BF){zed = SSPBUF;SSPCON1.SSPOV = 0;SSPCON1.WCOL = 0;}
}
//##############################################################################
 
 
 
 
 
 
 
void main() 
{
ADCON1=0b00001111;
TRISA.B0 = 0; //PORTD as output
PORTA.B0=0;
I2C_Slave_Init(0x18); //Initialize as a I2C Slave with address 0x30
while(1)
{
if(new==1)
{
PORTA.B0=1;
new=0;
}
}
}

 
post edited by ubuntuman - 2017/11/13 08:30:23
#70
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:15:06 (permalink)
+1 (1)
0XAA << 1 is quite probably wrong

GENOVA :D :D ! GODO
#71
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:16:01 (permalink)
0
Both work with external oscillator 4 MHZ crystal oscillator HS oscillator mode 
 
#72
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:24:05 (permalink)
0
DarioG
0XAA << 1 is quite probably wrong


I was just trying a piece of address that someone post in somewhere but now i put 0x30 in master and 0x18 in slave 
dont worry it is all useless 0xAA or 0xAA<<1 or 0x30 or 0x18 or even 0x00 with general call address
post edited by ubuntuman - 2017/11/13 08:29:06
#73
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:36:44 (permalink)
+1 (1)
Well, I may agree Smile
But I would not trust much General Call (I never used it) and I'd stick on "correct values" for the tests...

GENOVA :D :D ! GODO
#74
rodims
Super Member
  • Total Posts : 1478
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:39:20 (permalink)
+1 (1)
You did not show your includes. Ensure that your are only using include xc.h nothing else.
 
Its not useless to know which 'real'code you are testing, because you are representing us results for different code variants.
E.g. 0xAA << 1 evaluates as 0x54 and that will never work with your slave config, thus obscuring any other relevant detail or effort. 
#75
rodims
Super Member
  • Total Posts : 1478
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:42:31 (permalink)
+1 (1)
DarioBut I would not trust much General Call (I never used it) and I'd stick on "correct values" for the tests...

+1
Agreed, and as I already said, please better turn that off. You already tested that it does not help.
#76
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 08:44:52 (permalink)
+1 (1)
May I suggest a different approach?
 
I.e. can you try your MAster code with a known slave device, such as a TC74 temperature sensor or a 24xx1025 memory? You can get them for free by Microchip.
 
This way you would get something that works , and move on from that.

GENOVA :D :D ! GODO
#77
rodims
Super Member
  • Total Posts : 1478
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 09:15:00 (permalink)
+1 (1)
 [deleted, due to nonsense]
running out of ideas ...
 
edit: Btw, Proteus has an i2c Debugger component, but not sure whether this will help ubuntman.
Ideally this would allow test the master and the slave separately. I read that the component can replace the master,- not sure about the slave.
post edited by rodims - 2017/11/13 09:31:31
#78
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 10:14:30 (permalink)
+1 (1)
rodims
DarioBut I would not trust much General Call (I never used it) and I'd stick on "correct values" for the tests...

+1
Agreed, and as I already said, please better turn that off. You already tested that it does not help.


I turned it off . dont worry as i said i have now 0x30 in master code to write and 0x18 in slave code as an address 
#79
ubuntuman
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2016/05/02 15:28:40
  • Location: 0
  • Status: offline
Re: TWo PIC 18f4620 , one as master & the second is slave I2C communication problem 2017/11/13 10:18:32 (permalink)
0
rodims
You did not show your includes. Ensure that your are only using include xc.h nothing else.
 
Its not useless to know which 'real'code you are testing, because you are representing us results for different code variants.
E.g. 0xAA << 1 evaluates as 0x54 and that will never work with your slave config, thus obscuring any other relevant detail or effort. 


I use "Mikroc For PIC 6.0" compiler no need to use any includes . i include all libraries and he compile my code no need to write "#include something.h" here 
#80
Page: < 12345.. > >> Showing page 4 of 9
Jump to:
© 2019 APG vNext Commercial Version 4.5