• AVR Freaks

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

Page: << < ..6789 > Showing page 8 of 9
Author
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 05:27:45 (permalink)
0
Any one have suggestion about where else i can find help in this ? 
who should i speak with ? 
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/15 05:31:33 (permalink)
0
Now you have a working Master.
Can you post the latest Slave code you tried?

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 05:41:13 (permalink)
0
The complete Master code . HS oscillator mode .4MHZ

const long int crystalOscillator =4000000;
unsigned short int temp=0;
//#####################################################################################
void I2C_Master_Init(const unsigned long int c)
{
SSPCON1 = 0b00101000;
SSPCON2 = 0;
SSPADD = (crystalOscillator/(4*c))-1;
SSPSTAT = 0b11000000;
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 int 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
//I2C1_Init(50000);
OSCTUNE.PLLEN=0;
Delay_ms(500);
TRISB=0;
PORTB=0;
while(1)
{
 
I2C_Master_Start();
I2C_Master_Write(0xAA); //Write data
//I2C_Master_Write(0x00);
I2C_Master_Stop();

Delay_ms(5000);
}
}

The complete Slave code . HS oscillator mode .4MHZ

 
//##############################################################################
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;
zed = SSPBUF;
PIR1.SSPIF = 0;
SSPCON1.CKP = 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.R_W)
{
while(!SSPSTAT.BF){};
while(SSPSTAT.BF){dataRead = SSPBUF;}
SSPCON1.CKP = 1;
}
else if(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 = 0b11000000;
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=0b00011000;
LATC= 0b00011000;
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()
{
OSCTUNE.PLLEN=0;
ADCON1=0b00001111;
TRISA.B0 = 0; //PORTD as output
PORTA.B0=0;
I2C_Slave_Init(0xAA); //Initialize as a I2C Slave with address 0x30
while(1)
{
if(new==1)
{
PORTA.B0=1;
new=0;
}
}
}

post edited by ubuntuman - 2017/11/15 06:01:15
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/15 05:56:26 (permalink)
+1 (1)
Are you receiving any IRQ at the slave or none?
 
Also, this makes no sense:
(!SSPSTAT.D_A||SSPSTAT.D_A)
 
 

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:04:20 (permalink)
0
DarioG
Are you receiving any IRQ at the slave or none?
 
Also, this makes no sense:
(!SSPSTAT.D_A||SSPSTAT.D_A)

 
 


Ok . i edit it . but the point for me is is to get MSSP interrupt works"PIR1.SSPIF=1" . Handling it later in the routine is an easy matter . 
if u ask how i know if the interrupt of PIR1.SSPIF is happen. i make a variable named it new it will be equal to 1 once PIR1.SSPIF =1 then if the variable new becomes 1 so  a LED on PORTA.B0 will be 1 
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/15 06:06:05 (permalink)
0
Yes I've seen the variable:
I was asking "do you get ANY PIR1.SSPIF =1" or no?

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:08:51 (permalink)
+1 (1)
DarioG
Yes I've seen the variable:
I was asking "do you get ANY PIR1.SSPIF =1" or no?


No . Negative chief  The LED is Dead
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/15 06:11:06 (permalink)
+1 (1)
I'd use:
 SSPSTAT = 0b10000000;
SSPADD = address;
SSPCON1 = 0b00110110;
SSPCON2 = 0b00000000;

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:16:27 (permalink)
0
i did . no change 
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/15 06:18:32 (permalink)
+1 (1)
Are you sure your slave is running at all?
 
Can you insert a blinkling led in while() loop?
 
Can you try disabling IRQ and testing SSPIF in the loop, like
 PORTA.B1=PIR1.SSPIF;

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:28:02 (permalink)
+1 (1)
DarioG
Are you sure your slave is running at all?
 
Can you insert a blinkling led in while() loop?
 
Can you try disabling IRQ and testing SSPIF in the loop, like
 PORTA.B1=PIR1.SSPIF;


i used 
PORTA.B0=PIR1.SSPIF;
and led still dead 
 
then i used 
PORTA.B0=~PORTA.B0;
and the led was dancing like a stripper in Disco SLAVE is ALive
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/15 06:32:47 (permalink)
0
grin
but you disabled irq, did you?

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:40:17 (permalink)
+1 (1)
 
INTCON.PEIE = 0;
INTCON.GIE = 0;
PIE1.SSPIE = 0;
PIR1.SSPIF = 0;

yes chief
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/15 06:48:07 (permalink)
0
I see,
let's suppose it's a SIMulator bug then...

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:49:19 (permalink)
0
but it is them same in hardware too so , is it 18f4620 hardware bug? LoL: LoL
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/15 06:51:05 (permalink)
0
You said you had no hardware for testing Smile
 

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:53:50 (permalink)
+1 (1)
DarioG
You said you had no hardware for testing 
 


i has the twp pic 18f4620 boards testing same as in the bitmap screenshot here 
what i said that i dont have is TC74 
https://imgur.com/jQMNjA4
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/15 06:56:38 (permalink)
+1 (1)
I see, ok then.
 
btw, your schematics is missing decoupling capacitors...

GENOVA :D :D ! GODO
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/15 06:58:02 (permalink)

GENOVA :D :D ! GODO
ubuntuman
Super Member
  • Total Posts : 234
  • 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/15 06:58:59 (permalink)
0
for SCL SDA pins ???
Page: << < ..6789 > Showing page 8 of 9
Jump to:
© 2019 APG vNext Commercial Version 4.5