PICLeo
Joined: 14 Dec 2005 Posts: 11 Location: South Africa
|
I2C whatever |
Posted: Mon Jan 23, 2006 4:12 am |
|
|
Hi
Since a few days I try to get two 18F242 connected. Here the code.
MASTER:
Code: |
BYTE data;
#int_TIMER1
TIMER1_isr()
{
output_high(PIN_B3);
i2c_start();
i2c_write(0xa0);
i2c_write(0xEE);
i2c_start();
i2c_write(0xa1);
data = i2c_read(0);
i2c_stop();
printf("|%x|",data);
delay_ms(20);
output_low(PIN_B3);
}
void main()
{
output_high(PIN_B4);
delay_ms(2000);
output_low(PIN_B4);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
while(1)
{}
}
|
Slave:
Code: |
enum {address,data};
int mode;
BYTE data1 = 0;
BYTE BUFFER;
#int_SSP
SSP_isr()
{
BYTE ch;
output_high(PIN_B4);
if(i2c_poll())
{
ch = i2c_read(1);
if(mode == address)
{
mode = data;
}
else
{
data1 = ch;
mode = address;
printf("|%x|", data1);
}
}
else i2c_write(0xEE);
delay_ms(20);
output_low(PIN_B4);
}
void main()
{
output_high(PIN_B4);
delay_ms(2000);
output_low(PIN_B4);
enable_interrupts(INT_SSP);
enable_interrupts(global);
mode = address;
while(1);
}
|
So.
I check the send values via Hyper Terminal.
And thats my problem:
At the slave output I am getting permanently the address of the PIC |a0||a0|... and so on and not the |EE||EE|....
And at the master output |ff||ff| ....
Is there something wrong with the routines or do I have to clear the input buffer of the slave PIC? Because I think the code "should" work. I also screened the signal on the scope. And till the write command everything looks fine.
It would be very nice if somebody could help me. I tried it now to long without result.
BYE |
|