Problem with connection I2C Master - Slave dsPIC30F3010

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
rodrigo mendez
Posts: 11
Joined: 05 May 2009 15:44

Problem with connection I2C Master - Slave dsPIC30F3010

#1 Post by rodrigo mendez » 04 Jan 2010 03:57

Dear Gentlemen:

I need your support with library I2C, I need make protocol with interface I2C Mater-Slave between 2 dspICs.

I studied the information about the datasheet of this IC and the information about the library.

I understood and i followed the information that show in the example:

"I2c_Test (Demonstration on usage of I2C Library functions)";

But, i want to know how make i one interface to make:

* Master - Slave.
* Slave - Master.

I made the following:

FIRST dsPIC - MASTER, PROGRAM:

unsigned dAddr;
unsigned int datai2c,adcRes,andadc;

void main() {

ADPCFG = 0xFFFF;
PORTB = 0x00FF;
TRISE = 0x0000;

TRISBbits.TRISB3 = 1; // set pin as input - needed for ADC to work


I2C1_Init(10000);
dAddr = 0x00;
andadc = 0x00ff;


while (1) {

adcRes = Adc_Read(3);
adcRes = andadc & adcRes;
datai2c = adcRes;

Delay_100ms();


I2C_Start(); // issue I2C start signal
I2C_Write(0x01); // send byte via I2C according
// TABLE 17-1: 7-BIT I2C
// SLAVE ADDRESS - from datasheet dspic30f3010 )
I2C_Write(dAddr); // send byte (whats is the address location ??)
I2C_Write(datai2c); // send data ADC
// (whats is the data to be written ??)
I2C_Stop();

Delay_100ms();


}
}//~!


SECOND: dsPIC SLAVE - PROGRAM:

int *dAddr;
int take;
int bit7add;

void main() {

ADPCFG = 0xFFFF;
TRISE = 0x0000;

dAddr = 0xF0;


while (1) {


I2C_Init(100000);
I2C_Wait_For_Idle(); // acording the explain this function is to
// Waits for the I²C bus to become free.
// This is a blocking function.
take = I2C_Read(1); // Reads a byte from the I²C bus.


}

}//~!


Please, I need your support and these is my questions.

1. I want know and learn how make this interface correctly. I studied and I made different test & examples but i don´t have results.

2. if is possible One example in Master -Slave and Slave - Master Interface I2C ???

Please, is very important to us to know how use this protocol using I2C.

Thank for Your Attention.

Best Regards,

Rodrigo

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”