Hi folks!
I have connected two processors with serial cable.
First processor sending simple string "1234567890#" every second:
[code:1:4d76f0b6a2]
do
waitms 1000
ADCHEX = "1234567890#"
print ADCHEX
loop[/code:1:4d76f0b6a2]
Second processor catch data with serial buffered interrupt routine
[code:1:4d76f0b6a2]'****************************************************************
' Compiler directives
'****************************************************************
$projecttime = 46
$regfile = "m1280def.dat" ' specify the used micro
$crystal = 18432000 ' used crystal frequency
$hwstack = 1024
$swstack = 1024
$framesize = 512
'****************************************************************
' MCU hardware configuration
'****************************************************************
Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 64
Config Serialout = Buffered , Size = 128
Config Serialin1 = Buffered , Size = 32 , Bytematch = 10
Config Serialout1 = Buffered , Size = 32
Open "COM2:" For Binary As #2[/code:1:4d76f0b6a2]
So I catch character 10 which is last byte of message. I thought when get character 10, I'll use normal INPUT function to get data
Since I send 11 bytes string, I configured variable for input string as:
Dim ADCHEX as String * 11
First I check is all bytes are received, this is interrupt routine:
[code:1:4d76f0b6a2]temp1 = 0
do
temp = Waitkey(#2)
incr temp1
Print #2 , asc(temp)
temp = ISCHARWAITING(#2)
loop until temp = 0
Print #2 , "Total=" ; temp1[/code:1:4d76f0b6a2]
I got 13 bytes, and this is result from terminal window
[code:1:4d76f0b6a2]49
50
51
52
53
54
55
56
57
48
35
13
10
Total=13
[/code:1:4d76f0b6a2]
So this is work. I got all bytes, so I change interrupt routine to this:
[code:1:4d76f0b6a2]Input #2 , ADCHEX
print #2 , ADCHEX[/code:1:4d76f0b6a2]
[code:1:4d76f0b6a2]1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890[/code:1:4d76f0b6a2]
So for every received line # character is missing. ????? What ?
So, again I change routine to see what I got after INPUT routine
[code:1:4d76f0b6a2]
Input #2 , ADCHEX
temp = INSTR(ADCHEX , "#")
Print #2 , LEN(ADCHEX) ; " " ; temp
[/code:1:4d76f0b6a2]
Wanted to see where # character is ..... This is result :
[code:1:4d76f0b6a2]11 0
11 0
11 0[/code:1:4d76f0b6a2]
No, # is not inside.
But len is 11 ! What is inside ADCHEX string then ? So lets see:
[code:1:4d76f0b6a2]
Input #2 , ADCHEX
length = LEN(ADCHEX)
For temp = 1 to length
temp2 = mid(ADCHEX , temp , 1)
temp1 = asc(temp2)
print #2 , temp1
next
print #2 , "..end.."
[/code:1:4d76f0b6a2]
This is result
[code:1:4d76f0b6a2]
49
50
51
52
53
54
55
56
57
48
35
..end..
10
49
50
51
52
53
54
55
56
57
48
..end..
10
49
50
51
52
53
54
55
56
57
48
..end..
10
49
50
51
52
53
54
55
56
57
48
..end..
10
49
50
51
52
53
54
55
56
57
48
..end..
10
49
50
51
52
53
54
55
56
57
48
..end..
etc
etc
[/code:1:4d76f0b6a2]
So, only first time string is ok.:
[code:1:4d76f0b6a2]49
50
51
52
53
54
55
56
57
48
35[/code:1:4d76f0b6a2]
For all other inputs:
[code:1:4d76f0b6a2]
10
49
50
51
52
53
54
55
56
57
48[/code:1:4d76f0b6a2]
First character is 10 ????
I had try to modify all parameters including serial buffer buffers, $hwstack, $swstack, $framesize. No help.
Finaly I had change from
Dim ADCHEX as String * 11 to Dim ADCHEX as String * 12
and.... I got whole string, But this is not ok since first character is still 10:
[code:1:4d76f0b6a2]
49
50
51
52
53
54
55
56
57
48
35
..end..
10
49
50
51
52
53
54
55
56
57
48
35
..end..
10
49
50
51
52
53
54
55
56
57
48
35
..end..[/code:1:4d76f0b6a2]
But, I have to mention, that I write several routines using input routines on buffered com COM1, without any single problem.
So, what can be the source of problem ?
Regards!
Mladen Bruck
[b:4d76f0b6a2][color=red:4d76f0b6a2](BASCOM-AVR version : 2.0.7.6 )[/b:4d76f0b6a2][/color:4d76f0b6a2]
↧