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

pic24F16KA102 and I2C problem

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



Joined: 06 Sep 2011
Posts: 3

View user's profile Send private message

pic24F16KA102 and I2C problem
PostPosted: Tue Sep 06, 2011 3:55 am     Reply with quote

Hello,
I'm trying to make a 24F16KA102 work in slave I2C mode. As I wasn't able to make it run, then I tried to make a tiny test program to make this micro work as a I2C master. I used the 24 bits wizard of PCWHD 4.109 and I get the following code:
Code:

#include <24F16KA102.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOBSS                    //No boot segment
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES PR                       //Primary Oscillator
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES OSCIO                    //OSC2 is general purpose output
#FUSES POSCFREQ_H           
#FUSES SOSC_HIGH             
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES NOBROWNOUT               //No brownout reset
#FUSES PUT                      //Power Up Timer
#FUSES BORV_LOW             
#FUSES MCLR                     //Master Clear pin enabled
#FUSES ICSP1                    //ICD uses PGC1/PGD1 pins
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES DSWDT2147483648       
#FUSES DSWDTCK_LPRC         
#FUSES NODSBOR               
#FUSES NODSWDT               
//#FUSES NOALTI2C                   //I2C mapped to SDA1/SCL1 pins

#use delay(clock=20000000)



#use i2c(Master,slow,sda=PIN_B9,scl=PIN_B8,force_hw,NOFLOAT_HIGH)

void main()
{


   setup_wdt(WDT_Off);
   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);



   // TODO: USER CODE!!

 // prueba de funcionamiento...
 
 output_high(PIN_A6);// this is only an start-up check signal
 delay_ms(500);
 output_low(PIN_A6);
 delay_ms(500);
 output_high(PIN_A6);
 delay_ms(500);
 output_low(PIN_A6);
 
 while(1) {
 
 i2c_start();
 i2c_write(0xa2);
 i2c_write(123);
 i2c_stop();
 
 delay_ms(20);
 
 }
}

NOTES:

I used both #FUSES NOALTI2C and #FUSES ALTI2C.
I also used forced_hw and forced_sw.
I tried #use i2c for 'slow' and 'fast'.
NOFLOAT_HIGH

I always got no signals at all at PIN_B9 and PIN_B8. They are always at low level.

What is the problem?
Someone has a checked and tested right master i2c program using B9 & B8 pins that I could test in my circuit?
Any sample code to make this micro work as slave using interrupts to get a single data from i2c?

Thanks in advance!
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Sep 06, 2011 4:02 am     Reply with quote

You have got the pull-up resistors on the I2C bus?.
I2C, is an 'active low' bus, with the devices _only_ pulling the lines down. The bus requires a pull-up resistor on each of the two lines to pull the signals high when they are not driven. Typically something like 1.2 to 4.7KR for 5v I2C (depending on the bus length/capacitance), and dropping by 50% for a 3.3v I2C bus.

Best Wishes
eca



Joined: 06 Sep 2011
Posts: 3

View user's profile Send private message

PostPosted: Tue Sep 06, 2011 6:40 am     Reply with quote

Hi,

Couldn't be used NOFLOAT_HIGH to force a high level instead of pull-ups?
This is intended only to check that the i2c module is working and clk and sda signals are generated.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Sep 06, 2011 8:58 am     Reply with quote

NOFLOAT_HIGH can't work with hardware I2C, with software I2C, it apparently misses to set the pins to output for PIC24 (TRISB.x = 0). You shouldn't connect I2C peripherals when NOFLOAT_HIGH is selected, otherwise you're creating a bus contention for SDA.
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