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

Qustion on I2c for 16F877A/16F877

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







Qustion on I2c for 16F877A/16F877
PostPosted: Wed Aug 11, 2004 8:04 pm     Reply with quote

Hi all,

A few month ago, I write code for PIC 16F877 i2c, which works fine, Today my boss ask me to write I2c for PIC 16F877A, it didn't produce any signal. My question is simple, is there any code I need to add just for PIC16F877A.

Following is PIC16F877A I2c , if I replace 16F877.h, the same code works for PIC16F877.

Code:

#include <16f877A.H>
#fuses hs, NOPROTECT, BROWNOUT, PUT, NOWDT, NOLVP
#use delay(clock= 20000000)
#use i2c(Master,fast,sda=PIN_C4, scl=PIN_C3, FORCE_HW)

//========================
#byte SSPADD = 0x93
main ()
{
SSPADD = 0x07;   
output_float(PIN_C3);
output_float(PIN_C4);
i2c_start();
i2c_write(0x1E);
i2c_write(0x0f);
i2c_start();
i2c_write(0x1f);
i2c_read(0);
i2c_stop();
while(1)
{
;

}

}


Thanks

Minmin
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 12:17 pm     Reply with quote

Quote:
A few month ago, I write code for PIC 16F877 i2c, which works
fine. Today my boss ask me to write I2c for PIC 16F877A, it didn't
produce any signal. My question is simple, is there any code I need to
add just for PIC16F877A.


I tested the 16F877A with PCM vs. 3.207, and it worked OK.
I got pulses on pins C3 and C4.

I changed your program so it would be a better test program.
I set it to do a continous i2c_write(), so that I could easily
see the pulses on my oscilloscope. Try the following program
with the 16F877A and see if it works for you. (Change the clock
frequency and XT fuse, as required to make it work on your board).

If it doesn't work, then post your version of the compiler.

Code:
#include <16F877A.H>
#fuses XT, NOPROTECT, BROWNOUT, PUT, NOWDT, NOLVP
#use delay(clock= 4000000)
#use i2c(Master,fast,sda=PIN_C4, scl=PIN_C3, FORCE_HW)
//========================
#byte SSPADD = 0x93

main()
{
SSPADD = 0x07;   

output_float(PIN_C3);
output_float(PIN_C4);

while(1)
  {
   i2c_write(0x55);
  }

}
tag-eng



Joined: 28 Jul 2004
Posts: 6

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

PostPosted: Thu Aug 12, 2004 2:09 pm     Reply with quote

i have a questions, kind of similar in that it is involving the i2c and 16f877. i am using the picdem2 plus board and want to read from the temerature sensor on it.

i think i am able to read it but everytime i do i get the same number, 255. knowing that that isn't the temperature, and as well looking at the sensor datasheet that i wouldn't have convert it i am curious why this isn't working.

my code is as follows:

Code:

#include <16F877.h>
#device adc=8
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=RS232,bits=8)
#fuses NOWDT,RC, NOPUT, NOPROTECT, BROWNOUT
#use i2c(Master,sda=PIN_C4,scl=PIN_C3,RESTART_WDT,FORCE_HW)

...

   i2c_Start();           // Set a START condition I2C Bus
   i2c_Write(10011010); // Address and Write Flag
   i2c_Write(0x01);       // Temperature Register
   i2c_Start();           // Set a START condition I2C Bus
   i2c_Write(10011011); // Address and Read Flag
   temp = i2c_Read(0); // Read Teperature
   i2c_stop();


thanks in advance!
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 3:11 pm     Reply with quote

Quote:

i2c_Start(); // Set a START condition I2C Bus
i2c_Write(10011010); // Address and Write Flag
i2c_Write(0x01); // Temperature Register
i2c_Start(); // Set a START condition I2C Bus
i2c_Write(10011011); // Address and Read Flag
temp = i2c_Read(0); // Read Teperature
i2c_stop();


Your i2c_write() function is sending an address of 10,011,010 in decimal. If you are going to send a Binary number you need to have '0b' preceeding the number to indicate that it is in Binary. Or, you could use '0x' to indicate a Hex number (0x9A). This might be why it's not working. Try changing the number format and try again. It's always the little things like this that bite people in the butt.

Ronald
tag-eng



Joined: 28 Jul 2004
Posts: 6

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

PostPosted: Fri Aug 13, 2004 6:50 am     Reply with quote

that was it. and you are correct its always the little things. thanks alot, i appericate it.
Guest








PostPosted: Mon Aug 16, 2004 11:06 am     Reply with quote

Hey,

Thanks for all the replies, the problem is hardware. I just fix it , Above code works correctly for PIC 16f877A

Minmin
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