Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2C Pic Communication

Status
Not open for further replies.

Beatha.Gaire.Gra

Newbie level 3
Joined
Jan 23, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
Ok so I am trying to get 2 Pic 18F452 to talk to each other over I2C using MPLABS C18. I am using proteus and loading in my programs for my slave and master pics into the 2 pics by right clicking and clicking 'edit Properties' and opening my programs in HEX in the program files tab.
However nothing seems to be happening. I am very new to I2C so I am more the likely missing something important here are my 2 pieces of code

Slave
Code:
#include <p18cxxx.h>
#include <stdlib.h>
#include <stdio.h>
#include <usart.h>
#include <i2c.h>

#pragma config WDT = OFF
#pragma config OSC = XT     
#pragma config PWRT = OFF

int Address;
int Number;
char Letter;
char str[10];




void main( void )
{

	OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
				USART_EIGHT_BIT &USART_CONT_RX, 25);
 	TRISC=0x00;
	PORTC=0;
	
	OpenI2C(SLAVE_10, SLEW_OFF);
	while(1)
	{	
		while (BusyUSART());

		while(DataRdyI2C()==0);	

		Number=getcI2C();

			AckI2C();
	
		ultoa( Number, str );
		while (BusyUSART());
	    putsUSART( str ); 
	}
}





Master
Code:
#include <p18cxxx.h>
#include <stdlib.h>
#include <usart.h>
#include <i2c.h>

#pragma config WDT = OFF
#pragma config OSC = XT     
#pragma config PWRT = OFF

int Address=0b00000000;
int Number=22;
char Letter='A';


void main( void )
{
 	TRISC=0x00;
	PORTC=0;
	
	OpenI2C(MASTER, SLEW_OFF);
	while(1)
	{
		IdleI2C();
		StartI2C();
		WriteI2C(Address);
		while(SSPCON2bits.ACKSTAT!=0);
		WriteI2C(Letter);
		while(SSPCON2bits.ACKSTAT!=0);
		IdleI2C();
		StopI2C();
		
	}
}

Thank you very much
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top