ALIARIF93
Junior Member level 1
- Joined
- Jun 24, 2012
- Messages
- 15
- Helped
- 0
- Reputation
- 4
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,421
Hello,
Can anybody help in PIC18f4520 Slave transmit problem
I've detected Slave address but data is not placed in SSPBUF register.
Here is my code:
#include<p18f4520.h>
#include<delays.h>
#pragma config BOREN = OFF
#pragma config PWRT =OFF
#pragma config LVP = OFF
#pragma config OSC = HS
#define SDA PORTCbits.RC4 //SERIAL DATA
#define SCL PORTCbits.RC3 // SERIAL CLOCK
#define IN1 PORTDbits.RD0
#define IN2 PORTDbits.RD1
#define EN PORTCbits.RC2
unsigned char ADRESS; //Store Address
unsigned char DATA_RECIEVE;
unsigned char DATA_TRANSFER;
unsigned char REGISTER;
unsigned char r_w,reg_adr;
unsigned char temp;
#pragma interrupt MY_ISR
void MY_ISR(void)
{
if(PIR1bits.SSPIF)
{
PIR1bits.SSPIF =0;
if((SSPSTATbits.S==1) &&(SSPSTATbits.R_W ==0) && (SSPSTATbits.D_A ==0) && (SSPSTATbits.BF) )//ADRESS RECIEVED
{
ADRESS = SSPBUF;
reg_adr = 1;
return;
}
if((SSPSTATbits.S==1) &&(SSPSTATbits.R_W ==0) && (SSPSTATbits.D_A ==1) && (SSPSTATbits.BF) ) //DATA RECIEVED
{
DATA_RECIEVE = SSPBUF; return;
}
if((SSPSTATbits.S==1) &&(SSPSTATbits.R_W ==1) && (SSPSTATbits.D_A ==0) ) //DATA RECIEVED
{
SSPCON1bits.CKP =0;
SSPBUF = 0x0F;
SSPCON1bits.CKP =1;
return;
}
}
}
#pragma code HIGH_VECT = 0x008
void HIGH_VECT(void)
{
_asm
GOTO MY_ISR
_endasm
}
#pragma code
void I2C_SLAVE_INITIALIZE(void)
{
TRISCbits.TRISC3 = 1;
TRISCbits.TRISC4 = 1;
SSPCON2 = 0x00;
SSPCON1 = 0x3E; //SLAVE Side 7bit address Configuration
SSPADD = 0x02; //SLAVE ADDRESS REGISTER = 0x01
SSPCON2bits.SEN = 1; //Enable Clock-Stretching!
SSPSTATbits.SMP = 1; //slew rate disabled => standard speed mode 100khz/
SSPSTATbits.CKE = 0; //Enable SMBus specific inputs
SSPCON2bits.GCEN = 1;
}
void main()
{
float temp;
ADCON1 = 0xFF;
TRISD = 0x00;
TRISB = 0x00;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PIE1bits.SSPIE = 1;
IPR1bits.SSPIP = 1;
TRISCbits.TRISC2 = 0;
TRISCbits.TRISC1 = 0;
DATA_RECIEVE =0;
I2C_SLAVE_INITIALIZE();
while(1)
{
}
}
Can anybody help in PIC18f4520 Slave transmit problem
I've detected Slave address but data is not placed in SSPBUF register.
Here is my code:
#include<p18f4520.h>
#include<delays.h>
#pragma config BOREN = OFF
#pragma config PWRT =OFF
#pragma config LVP = OFF
#pragma config OSC = HS
#define SDA PORTCbits.RC4 //SERIAL DATA
#define SCL PORTCbits.RC3 // SERIAL CLOCK
#define IN1 PORTDbits.RD0
#define IN2 PORTDbits.RD1
#define EN PORTCbits.RC2
unsigned char ADRESS; //Store Address
unsigned char DATA_RECIEVE;
unsigned char DATA_TRANSFER;
unsigned char REGISTER;
unsigned char r_w,reg_adr;
unsigned char temp;
#pragma interrupt MY_ISR
void MY_ISR(void)
{
if(PIR1bits.SSPIF)
{
PIR1bits.SSPIF =0;
if((SSPSTATbits.S==1) &&(SSPSTATbits.R_W ==0) && (SSPSTATbits.D_A ==0) && (SSPSTATbits.BF) )//ADRESS RECIEVED
{
ADRESS = SSPBUF;
reg_adr = 1;
return;
}
if((SSPSTATbits.S==1) &&(SSPSTATbits.R_W ==0) && (SSPSTATbits.D_A ==1) && (SSPSTATbits.BF) ) //DATA RECIEVED
{
DATA_RECIEVE = SSPBUF; return;
}
if((SSPSTATbits.S==1) &&(SSPSTATbits.R_W ==1) && (SSPSTATbits.D_A ==0) ) //DATA RECIEVED
{
SSPCON1bits.CKP =0;
SSPBUF = 0x0F;
SSPCON1bits.CKP =1;
return;
}
}
}
#pragma code HIGH_VECT = 0x008
void HIGH_VECT(void)
{
_asm
GOTO MY_ISR
_endasm
}
#pragma code
void I2C_SLAVE_INITIALIZE(void)
{
TRISCbits.TRISC3 = 1;
TRISCbits.TRISC4 = 1;
SSPCON2 = 0x00;
SSPCON1 = 0x3E; //SLAVE Side 7bit address Configuration
SSPADD = 0x02; //SLAVE ADDRESS REGISTER = 0x01
SSPCON2bits.SEN = 1; //Enable Clock-Stretching!
SSPSTATbits.SMP = 1; //slew rate disabled => standard speed mode 100khz/
SSPSTATbits.CKE = 0; //Enable SMBus specific inputs
SSPCON2bits.GCEN = 1;
}
void main()
{
float temp;
ADCON1 = 0xFF;
TRISD = 0x00;
TRISB = 0x00;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PIE1bits.SSPIE = 1;
IPR1bits.SSPIP = 1;
TRISCbits.TRISC2 = 0;
TRISCbits.TRISC1 = 0;
DATA_RECIEVE =0;
I2C_SLAVE_INITIALIZE();
while(1)
{
}
}