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 support@ccsinfo.com

Bit-Bang I2C - PIC18F

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



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Bit-Bang I2C - PIC18F
PostPosted: Tue Jul 08, 2003 9:35 pm     Reply with quote

I'm trying to ascertain if and how one needs to set the tris register for the scl and sda pins when using CCS bit-bang I2C routines. I did make the necessary pins (A0 and A1) digital via the ADCON1 register. Do I need to set the TRIS or do the CCS routines do it for me? I'm also using the built in USART for RS-232 and wonder if that's a problem.

PIC18F1320, 40Mhz, PCWH 3.163 (and I tried 3.167 also)

Anyone know if/what I'm doing wrong?
Thanks.

John

Here's sample code:

#fuses H4, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(Clock=40000000)
#use RS232(baud=19200, bits=8, BRGH1OK, xmit=PIN_B1, rcv=PIN_B4, PARITY=N)

#use i2c(master, scl=PIN_A0, sda=PIN_A1)


#asm
bsf adcon1,0
bsf adcon1,1
#endasm

.......

i2c_start();
i2c_write(0x40);
i2c_write(255);
i2c_stop();

.....

i2c_start();
i2c_write(0x41);
readtemp = i2c_read();
i2c_stop();



___________________________
This message was ported from CCS's old forum
Original Post ID: 144515797
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

Re: Bit-Bang I2C - PIC18F
PostPosted: Tue Jul 08, 2003 10:01 pm     Reply with quote

:=I'm trying to ascertain if and how one needs to set the tris register for the scl and sda pins when using CCS bit-bang I2C routines. I did make the necessary pins (A0 and A1) digital via the ADCON1 register. Do I need to set the TRIS or do the CCS routines do it for me? I'm also using the built in USART for RS-232 and wonder if that's a problem.
:=
:=PIC18F1320, 40Mhz, PCWH 3.163 (and I tried 3.167 also)
:=
:=Anyone know if/what I'm doing wrong?
:=Thanks.
:=
:=John
:=
:=Here's sample code:
:=
:=#fuses H4, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(Clock=40000000)
:=#use RS232(baud=19200, bits=8, BRGH1OK, xmit=PIN_B1, rcv=PIN_B4, PARITY=N)
:=
:=#use i2c(master, scl=PIN_A0, sda=PIN_A1)
:=
:=
:=#asm
:=bsf adcon1,0
:=bsf adcon1,1
:=#endasm
:=
:=.......
:=
:=i2c_start();
:=i2c_write(0x40);
:=i2c_write(255);
:=i2c_stop();
:=
:=.....
:=
:=i2c_start();
:=i2c_write(0x41);
:=readtemp = i2c_read();
:=i2c_stop();
:=
:=
:=

John,
Haven't actually done it, but I think you only need to float the lines.

output_float(PIN_A0);
output_float(PIN_A1);

Also, I think that
readtemp = i2c_read();
should be
readtemp = i2c_read(0);
because the first byte is also the last and need to NACK it.

Regards
Kenny
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515798
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