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

Problem with i2c and the TRIS settings

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



Joined: 04 Jan 2008
Posts: 1

View user's profile Send private message

Problem with i2c and the TRIS settings
PostPosted: Fri Jan 04, 2008 3:32 am     Reply with quote

Need help with a problem using i2c to communicate with either E2 or a RTC. The problem lies in getting the i2c to work properly.

Compiler ver. 4.064
using a PIC18F65j10

When this problem ocurred i created this small test program to rule out any side effects from the other code.

Code:
// Debugging I2C
#include "18F65J10.h"   
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=8000000)
#use i2c(master,scl=PIN_C3,sda=PIN_C4,force_hw,fast=400000,stream=RTCE2)

void main(){   set_tris_b( 0xFC );
   set_tris_c( 0x98 );
   set_tris_d( 0x00 );
   set_tris_e( 0xFF );
   set_tris_f( 0x00 );
   set_tris_g( 0x1c );
   
   while(1){
      i2c_start(RTCE2);            // Pull bus low
      i2c_write(RTCE2, 0xA2);         // Send slave adress, write cmd
      i2c_write(RTCE2, 0x03);         // Adress where data will be written
      i2c_write(RTCE2, 0xAA);         // Test data
      i2c_stop(RTCE2);
      delay_ms(500);
   }
}   


But even this simple program presents me with the same problem which is: The previous code will result in a totally silent i2c. To get the i2c up and running i must first set tris_c pin c3 & c4 ( SCL & SDA) to outputs and thereafter setting the pins to inputs again. Following code will get the i2c to work as it should

Code:
// Debugging I2C
#include "18F65J10.h"   
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=8000000)
#use i2c(master,scl=PIN_C3,sda=PIN_C4,force_hw,fast=400000,stream=RTCE2)

void main(){   
   set_tris_b( 0xFC );
   set_tris_c( 0x80 );   // SDA & SCL outputs
   set_tris_c( 0x98 );   // SDA & SCL inputs
   set_tris_d( 0x00 );
   set_tris_e( 0xFF );
   set_tris_f( 0x00 );
   set_tris_g( 0x1c );
   
   while(1){
      i2c_start(RTCE2);            // Pull bus low
      i2c_write(RTCE2, 0xA2);         // Send slave adress, write cmd
      i2c_write(RTCE2, 0x03);         // Adress where data will be written
      i2c_write(RTCE2, 0xAA);         // Test data
      i2c_stop(RTCE2);
      delay_ms(500);
   }
}   
   


By setting SDA & SCL to outputs then inputs will get the i2c to work. But once the i2c has started to work I can program it with the first code again and it will still work as long as the only warm reset ocurres. Unplugging the voltage to the PIC will force me to program the TRIS C as output and thereafter as inputs to get it to work again. According to MPLAB the trisc is set correctly with both programs but only the second works. The i2c communication problem is verified using oscilloscope. Any ideas? What am I missing?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Jan 04, 2008 9:59 am     Reply with quote

Do you really need to be controlling the tris? It should only be used in conjunction with fast_io. I like to allow the compiler to control the I/O when I'm working with I2C. I haven't tried controlling the tris manually with I2C communications but I would imagine it would cause problems since it needs to be switched from input to output and back while communicating.

Ronald
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jan 04, 2008 2:07 pm     Reply with quote

A very strange startup problem. What do you have connected to the I2C lines? Are all required pull-up resistors in place?

What is the silicon revision of your chip?
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