Am I reading your code correctly? You have an interrupt inside an interrupt?
If so, I do not think that will work?
Am I reading your code correctly? You have an interrupt inside an interrupt?
If so, I do not think that will work?
Dave
Always wear safety glasses while programming.
It may be possible the problem is in your crc16 or some other related section. In the code you posted, I do not see any led(did I miss it?)
This code appears Ok to me.
Define very large. Your buffer length seems to be 20 bytes so if the frame is longer than that I imagine you'll be in trouble. It shouldn't stop interrupting though.....I have noticed that if the frame or the values are very large, I lose communication
I can't seem to find where you turn on the LED you mentioned.
/Henrik.
Hello everyone sorry did not reply earlier.
hello mackrackit , is enabled every time it happens the serial interrupt. is used to determine if there are no more characters to read and works. original code from modbus.pl
If (NewFrame = 1) OR (Length = 0) then 'New modbus frame start
NewFrame = 0
T2CON.2 = 1 ' Enable Timer2
Length = 1
EndIf
hello Jerson, the crc16 is working, the led is switched off in the Main, is switched on every time PIR1.5 = 1. when the fault occurs, the LED lights (I'm in the interruption) and then turn off.
hello HenrikOlsson, explain why "Define very large", look:
while (PIR1.5 = 1) 'Write modbus frame to buffer
buffer[Length] = RCREG
Length = Length + 1
if Length >=20 then ' here check buffer
Length = 0
EndIf
wend
Last edited by scrwld; - 16th September 2010 at 20:28.
Hi,
You said that the problem occured when the frame was large and I was asking HOW large.
The reason I asked is that your buffer wraps around when Length is 20 you only have space for 21 characters in your buffer.
You get you characters from RCREG and put them in Buffer[0], Buffer[1], Buffer[2].......Buffer[20]. When Length reaches 20 it wraps around to 0 and you overwrite what's in Buffer[0] and because you said the problem occured when the frame was "very large". So, is it when the frame is larger than 20 bytes?
/Henrik.
Bookmarks