PDA

View Full Version : string&i2c



cesurcelik
- 17th February 2006, 16:41
hi all.
what i want to do is sending string from pc-hyperterminal via pic16f876 to i2c then reading i2c
my code is:
INCLUDE "MODEDEFS.BAS"
DEFINE CHAR_PACING 65000
DEFINE OSC 20
CONTROL CON $A0
DPIN VAR PORTC.4
CPIN VAR PORTC.3
VALUE VAR BYTE[21]
ADDRESS VAR BYTE

SERIN2 PORTC.7,396,[WAIT("Ee"),STR VALUE \ 21]

ADDRESS=0
WRITEX:

FOR ADDRESS=0 TO 20
I2CWRITE DPIN,CPIN,CONTROL,ADDRESS,[VALUE]
PAUSE 10
NEXT ADDRESS


READX:

FOR ADDRESS=0 TO 20

I2CREAD DPIN,CPIN,CONTROL,ADDRESS,[VALUE]
SEROUT2 PORTC.6,396,[#ADDRESS,"=",VALUE[ADDRESS],10,13]
NEXT ADDRESS
LOOP:
GOTO LOOP
END


when i send "EeABCDEFGHIJKLMNPRSTUV" to i2c
the response is:

Òú
1:B
2:C
3:D
4:E
5:F
6:G
7:H
8:I
9:J
10:K
11:L
12:M
13:N
14:P
15:R
16:S
17:T
18:U
19:V
20:
as you see the ,i can't read the first address and value(0=A),i don't understand why?

tank you

beto
- 17th February 2006, 16:58
May be Your write Routine, test this:

WriteX
FOR ADDRESS=0 TO 20
I2CWRITE DPIN,CPIN,CONTROL,ADDRESS,VALUE[ADDRESS]
PAUSE 10
NEXT ADDRESS

cesurcelik
- 17th February 2006, 17:07
@beto
tanks for quick response.
i've alredy tryed what you said.but the responce is

êú
1=B
2=C
3=D
4=E
5=F
6=G
7=H
8=I
9=J
10=K
11=L
12=M
13=N
14=P
15=R
16=S
17=T
18=U
19=V
20=

there is no change

beto
- 17th February 2006, 17:21
You are using level shifters?, the problem then looks as voltage chirp, if you is using only resistors then try to set High the TX pin BEFORE Data transmition!

cesurcelik
- 17th February 2006, 17:38
@beto
thanks again
i did it as you said
now the response is:

0=ÿ
1=B
2=C
3=D
4=E
5=F
6=G
7=H
8=I
9=J
10=K
11=L
12=M
13=N
14=P
15=R
16=S
17=T
18=U
19=V
20=

i can see first address but not correct value