Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communication problem, HELP! — Parallax Forums

Serial Communication problem, HELP!

OlovAOlovA Posts: 23
edited 2008-11-20 12:28 in Propeller 1
Hi. I'm·new to the propeller, it's a really amazing little chip...
Now i have a problem that i cannot solve.
My code should just receive 8 characters from a pc, then resend it to the pc.
Sometimes the prop. doesn't resend more then 5 characters, and then when i send a new series of 8 ch.
then i get "the old one's"
I cannot figure out why...
Would appretiate some help! Many thank's from Olov in a snowy sweden...

Below i paste my code, it's only "PUB Main" that i use for the moment, i'll tried to make comments that u people should understand

I have some swedish in the beginning but i dont think it's important.



' 8-bit·· 8-bit··· 2*8-bit 2*8-bit·· 2*8-bit
' Byte Byte······· Hi/Lo·· Hi/Lo Byte Lo/Hi
'
' 081118
' Sänd med terminalprogram, S0100 för Servo 0, 100 %
' Sänd med terminalprogram, S0050 för Servo 0,· 50 %
' Sänd med terminalprogram, S0000 för Servo 0,·· 0 %
' S0 = Servo 0 ( P0 ), sedan 0 - 100 % = 1000 - 2000 ms
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· CRCPOLY = %1010000000000001
· MaxStrSize = 20
VAR
· byte DataStr1[noparse][[/noparse]MaxStrSize],Ptr,MyTestVar,Slav,ModFunk,H_Start,L_Start,H_Antal,L_Antal,L_CRC,H_CRC
· Byte Rx,TmpHi,TmpLo,CRC_Tmp,CRC_i,x
· word CRC
· long CogStack1[noparse][[/noparse] 20]

obj
· Serial· : "FullDuplexSerial"
· Servo : "Servo32v3"·
PUB main
· 'cognew(Servokontroll,@CogStack1) ' Startar sevofunktioner i ny cog eftersom cog0 blir väldigt upptagen med seriekommunikation
· 'MyTestVar := 100·
·
· Serial.start(31,30,0,9600)
·
· repeat
··· Ptr := 0··················· ' A pointer that keep's counting incoming ch.·································
···
···
··· repeat
····· DataStr1[noparse][[/noparse]ptr] := Serial.Rx' Store the character's in DataStr1 with index "Ptr" from 0 to 7
····· ptr++···················· ' Increase my index
··· while Ptr < 8·············· ' Continue until 8 characters received
····· Slav··· := DataStr1[noparse][[/noparse]0]··· ' Here i just "restore" them for future use
····· ModFunk := DataStr1[noparse][[/noparse]1]
····· H_Start := DataStr1[noparse][[/noparse]2]
····· L_Start := DataStr1[noparse][[/noparse]3]
····· H_Antal := DataStr1[noparse][[/noparse]4]
····· L_Antal := DataStr1[noparse][[/noparse]5]
····· L_CRC·· := DataStr1[noparse][[/noparse]6]
····· H_CRC·· := DataStr1[noparse][[/noparse]7]
··· repeat 20················· ' I put this line to see if the prop did this or not, it doesn't repeat send 20*8 ch.
····· waitcnt(1_000_000+cnt)·· ' I thought, maybe th Tx function need some time to finish te work, but no difference
····· repeat CRC_i from 0 to 7
······· Serial.tx(dataStr1[noparse][[/noparse]CRC_i]) ' This is where the prop should send 8 ch. every time the loop restart
···
PUB Servokontroll················ ' The code here is gor the future, not in use, not a problem
· dira[noparse][[/noparse]17]~~
·
· Servo.Set(0,1000)
· Servo.start
· repeat
··· waitcnt(10_000_000 + cnt)
··· Servo.Set(0,MyTestVar*10)
··· !OutA[noparse][[/noparse]17]· ' Visar att denna cog jobbar...
····
Pub Calc_crc····················· ' The code here is gor the future, not in use right now, not a problem
· CRC ^= CRC_tmp 'Xor
· Repeat CRC_i from 0 To 7
··· CRC >>= 1 'Shift right
··· If CRC & %0000000000000001
····· Next
··· CRC ^= CRCPOLY 'Xor with Poly
···

Comments

  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-11-20 12:28
    Im not sure here but check your indentation as it looks to me like your lower repeats are cycling each rx.
Sign In or Register to comment.