View previous topic :: View next topic |
Author |
Message |
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
dspic30f4013 and I2C slave mode |
Posted: Sun Feb 20, 2011 7:11 am |
|
|
can somebody tell me why this piece of code is NOT working?
Code: |
#include <30f4013.h>
#device adc=12
#FUSES WDT // Watch Dog Timer
#FUSES HS
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES HS2_pll8 // div by 2 and multiply the ext. clock of 30mhz /2 by 8x
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#define XTAL_FREQUENCY 120000000,RESTART_WDT
#use delay(clock=XTAL_FREQUENCY)
#use rs232(stream = RS232, baud=115200,parity=N,uart2,bits=8)
#use i2c(SLAVE, SDA=PIN_F2, SCL=PIN_F3, address=0x08,FORCE_HW)
/////////////////// Variabelen /////////////////
int led1;
/////////////////// UITGANGEN /////////////////
#define led PIN_B0 // output pen 5
/////////////////////////////////////////////////////////////////////////////////////
#INT_SI2C
void SSP_interrupt()
{
if (led1 == true)
{
output_low(led);
led1 = false;
}
else
{
output_high(led);
led1=true;
}
printf("i2c interrupt");
}
/////////////////////////////////////////////////////////////////////////////////////
Void main()
{
enable_interrupts(intr_GLOBAL);
enable_interrupts(int_SI2C);
enable_interrupts(int_MI2C);
While(1)
{
delay_ms(100);
restart_wdt();//at least one in the main while(1) loop
}
}
|
I want to use this controller as slave.
I have made a test of the I2c Address from the master with another 18f controller and this is working.
Many thanks |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Feb 20, 2011 8:05 am |
|
|
I guess, you have used the address coding for PIC18. It's different for dsPIC, if I remember right. Refer to the dsPIC family refernce manual. |
|
|
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
|
Posted: Sun Feb 20, 2011 8:15 am |
|
|
What do you mean with "diffrent address coding"?
i found in the last PCd manual this :
Code: | #use I2C(slave,sda=PIN_C4,scl=PIN_C3 address=0xa0,FORCE_HW) |
(Page 142, pcd manual Januari 2011) |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Feb 20, 2011 9:36 am |
|
|
The manual example clarifies, that the CCS guys aren't aware of the difference, because the 0xa0 is an invalid 7-Bit address with dsPIC. The value is written as is to the address register, but it holds a 7-Bit value.
But instead of guessing about the PCD manual, you may want to read the dsPIC handbook, as suggested, or simply try different address settings respectively poll the bus for I2C devices by the host. This is, what most practical men would do.
If I remember right, there has been a previous thread discussing the same issue. |
|
|
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
|
Posted: Sun Feb 20, 2011 9:53 am |
|
|
Quote: | that the CCS guys aren't aware of the difference, because the 0xa0 is an invalid 7-Bit address with dsPIC |
correct, for this reason i am using 0x08 as address
the PCD manual is Crap (Read : A bad rewritten version of the 18f manual)
now i am reading the reference manual... |
|
|
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
|
Posted: Wed Mar 16, 2011 3:48 pm |
|
|
still struggling with this problem... anyone plz? |
|
|
|