View previous topic :: View next topic |
Author |
Message |
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
two I2c i/f....slave is problemetic |
Posted: Wed Apr 04, 2007 7:01 am |
|
|
I am using a PIC as a I2C bridge...
for slave, i am using hardware and for master I am using software I2c..
software one is working fine....
while the hardware I2C is not working properly...
this is the code for HW..
once master accumlates the data, it will store and pass it to slave hw interface...
//===================
#INT_SSP
void i2c_interrupt_handler(void) // Interrupt handler for slave I2C
{
#use i2c(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0x60, FORCE_HW)
BYTE state;
state = i2c_isr_state();
if(state == 0x80) // Master is requesting data
{
for (i=0;i<4>>; // High byte of command
}
}
else if(state < 0x80) // Master is sending data
{
recvx = i2c_read();
ADC_store[1] = recvx;
}
} |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 04, 2007 11:18 am |
|
|
Your code is unreadable because you had HTML enabled when you
posted it. Also, I can tell from your placement of the #use i2c()
statement that you're new to CCS. You need to study the example
files. You need to start by using the example files instead of your own
code. That way, you can make something that works and learn from it.
Once you've done that, you can start creating your own code.
Suggestions:
Put the Ex_Slave.c program into your slave PIC.
That example file is in this folder: c:\Program Files\PICC\Examples
Use the code in this post for your Master PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=28097&start=9
This should work. It will also tell you if your hardware is working OK.
For example, do you have pull-ups on the SDA and SCL lines ?
Do you have a ground connection between the two boards ? |
|
![](templates/subSilver/images/spacer.gif) |
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
thanks |
Posted: Thu Apr 05, 2007 9:36 am |
|
|
HI PCM,
Thank you....
you helped me out with 60 % solution..
I am using Master and slave both together on My PIC...
if I use master only then it works, or only Slave code....
but when i tried to use both Master & slave...it clashes...
and transaction happens on slave side of PIC....
here is my code..
Code: |
#use i2c(SLAVE, SDA=PIN_B1, SCL=PIN_B4, address=0x60, FORCE_HW)
#INT_SSP
void i2c_interrupt_handler(void)
{
BYTE state,incoming;
state = i2c_isr_state();
if(state < 0x80)
{
incoming = i2c_read();
}
if(state == 0x80)
i2c_write(0x6B);
}
void main(void)
{
printf("Hello World\n"); // Say hello
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
#use i2c(MASTER, SDA=PIN_B2, SCL=PIN_B3)
i2c_start();
i2c_write(I2C_ADC);
i2c_write(SETUP_ADC);
i2c_write(CONFIG_ADC);
i2c_stop();
while(1)
{
i=0;
i2c_start();
i2c_write(I2C_ADC+1);
while (i!=8)
{
ADC_res.Isense[i] = (i2c_read());
printf("\rAD%d=%x\t",i,ADC_res.Isense[i]);
i++;
}
i2c_stop();
output_toggle(PIN_A2);
restart_wdt();
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Apr 05, 2007 9:57 am |
|
|
What chip?.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
tom_hanks
Joined: 04 Apr 2007 Posts: 20
|
|
Posted: Thu Apr 05, 2007 9:59 am |
|
|
PIC16F818
for slave:
Hardware I2C
for Master:
Software I2C
any one out there ?? |
|
![](templates/subSilver/images/spacer.gif) |
|