CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dspic30f4013 and I2C slave mode

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
on7nh



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

View user's profile Send private message Visit poster's website MSN Messenger

dspic30f4013 and I2C slave mode
PostPosted: Sun Feb 20, 2011 7:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 20, 2011 8:05 am     Reply with quote

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

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Sun Feb 20, 2011 8:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 20, 2011 9:36 am     Reply with quote

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

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Sun Feb 20, 2011 9:53 am     Reply with quote

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

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Wed Mar 16, 2011 3:48 pm     Reply with quote

still struggling with this problem... anyone plz?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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