|
|
View previous topic :: View next topic |
Author |
Message |
victor pasilla Guest
|
I2C slave not work |
Posted: Fri Jan 19, 2007 12:33 pm |
|
|
i am trying to communicate 2 pic using the I2C bus,
master generate sda and sdl signals, but the slave not responds,
this is the code for the master
....
..
#use I2C(master,sda=PIN_B0, scl=PIN_B1))
.....
.....
while (TRUE){
i2c_start();
if ( i2c_write(0xa1)==0){
resultadoADC[0] = i2c_read();
resultadoADC[1] = i2c_read();
}
i2c_stop();
delay_ms(100);
}
....
....
this is the code for the slave
...
...
#use I2C(slave,address=0xa0,sda=PIN_B0, scl=PIN_B1))
int8 resultadoADC[2];
int16 lectura;
#INT_SSP
void ssp_interupt ()
{
BYTE state;
state = i2c_isr_state();
if(state == 0x80) //Master is requesting data
{
output_toggle(pin_B5); //flag
resultadoADC[0]=make8(lectura,0);
resultadoADC[1]=make8(lectura,1);
i2c_write(resultadoADC[0]);
i2c_write(resultadoADC[1]);
}
}
void main (void){
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
i2c_SlaveAddr(0xa0);
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc( AN0);
set_adc_channel(0);
output_low(pin_B5);
while (TRUE){
lectura = read_adc();
output_toggle(pin_B4); // flag
}
}
can you helpme please |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 19, 2007 1:16 pm |
|
|
Which PIC |
|
|
Guest
|
|
Posted: Fri Jan 19, 2007 1:26 pm |
|
|
sorry,....
i am using two pics 18F4550 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|