|
|
View previous topic :: View next topic |
Author |
Message |
john cutler
Joined: 06 Sep 2003 Posts: 82 Location: Hot Tub, California
|
Bit-Bang I2C - PIC18F |
Posted: Tue Jul 08, 2003 9:35 pm |
|
|
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
|
Re: Bit-Bang I2C - PIC18F |
Posted: Tue Jul 08, 2003 10:01 pm |
|
|
:=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 |
|
|
|
|
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
|