Beatha.Gaire.Gra
Newbie level 3
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
Master
Thank you very much
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