Home › Forums › Microcontrollers › PIC Microcontroller › I2C Communication between two PIC16F877
Tagged: Communiation, i2c, PIC
- This topic has 1 reply, 2 voices, and was last updated 6 years, 11 months ago by Ligo George.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
April 4, 2016 at 4:34 pm #12298alekParticipant
Hi everyone;
I am trying to accomplish I2C communication between two PIC16F877. But I did not succeed. My codes in below. Can any body help me
Master PIC code :
#include <xc.h> #pragma config FOSC = XT #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config CP = OFF #pragma config BOREN = ON #pragma config LVP = ON #pragma config CPD = OFF #pragma config WRT = ON #define _XTAL_FREQ 4000000 void WaitC( void ) { while ( ( SSPCON2 & 0x1F ) || ( SSPSTATbits.R_W ) ) continue; } void StartC( void ) { SSPCON2bits.SEN = 1; while(SEN); } void StopC( void ) { SSPCON2bits.PEN = 1; while(PEN); } signed char WriteC( unsigned char veri ) { WaitC(); SSPBUF = veri; return(ACKSTAT); } void main(void) { TRISC = 0XFF; SSPCON = 0X38; SSPADD = 9; SSPSTAT = 0X80; SSPCON2 = 0X00; TRISB = 0; PORTB = 0; SSPSTATbits.R_W = 0; while(1) { StartC(); WriteC(0X22); WriteC(0X40); StopC(); __delay_ms(100); } }
Slave PIC code :
#include <xc.h> #pragma config FOSC = XT #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config CP = OFF #pragma config BOREN = ON #pragma config LVP = ON #pragma config CPD = OFF #pragma config WRT = ON #define _XTAL_FREQ 4000000 void interrupt KESME (void) { if(SSPIF == 1) { PORTB = 255; } SSPIF = 0; } void main(void) { TRISB = 0X00; PORTB = 0X00; TRISC = 0XFF; SSPIE = 1; PEIE = 1; GIE = 1; SSPCON = 0X36; SSPADD = 0X22; SSPSTAT = 0X00; SSPCON2 = 0X00; while(1) { } }
April 12, 2016 at 8:06 am #12352Ligo GeorgeKeymasterHi,
Sorry for the delay in reply. We were about to publish an article regarding this. So now, try the following link. -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.