View previous topic :: View next topic |
Author |
Message |
toto
|
Posted: Fri Sep 26, 2014 4:57 pm Post subject: Serial communication isr |
|
|
Hello,
Expected receive serial port 9 bytes like this
123 45 24 16 56 214 251 147 56 = 9 bytes 22 char
123 45 24 1 56 214 251 147 56 = 9 bytes 21 char
123 45 24 1 56 214 251 147 5 = 9 bytes 20 char
On Urxc Rec_isr 'define serial receive ISR
Enable Urxc 'enable receive isr
const cmaxchar = 21 ??????
Rec_isr:
D = Udr 'read UDR only once i think 1 char
D = inkey 'what we receive, a byte or just one char?????
If Bc < Cmaxchar Then 'does it fit into the buffer?
Incr Bc 'increase buffer counter
If D = 13 Then 'return?
Buf = Buf + Chr(0)
Bc = Cmaxchar 'at the end
Else
Buf = Buf + Chr(d) 'add to buffer
End If
End If
B = 1 'set flag
Return
How to modify the isr to indentify and get the 9 bytes to a byte array?
I not want use Ischarwaiting and Inputbin
Can i use this way in the Rec_isr to get everytime one byte with inkey, with d = inkey
Tahnks in advance
Best regards
toto
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Sep 27, 2014 8:38 am Post subject: |
|
|
Hi,
I'm using the following code to grab a RFID number from the Serial port. The Serial communications consist of:
First character 2 (dec)
Next 10 charcters RFID number
Next character checksum
Next character end of message character
Note the RFID_array is at the same address as the rfid_string so writing to rfid_arry changes rfid_string as well- You just Need to make sure that the end of string character (0) is at the end of the string.
Code: |
Dim Rfid_ptr As Byte 'RFID input pointer
Dim Rfid_have_buffer As Byte 'RFID data ready for decode
Dim Rfid_char As Byte 'Char from RFID
Dim Rfid_array(15) As Byte 'RFID checksum array
Dim Rfid_string As String * 12 At Rfid_array(1) + 1 Overlay 'String RFID Nr.
Serial_isr:
Rfid_char = Inkey(#1)
If Rfid_char = 2 Then 'Chr 2 - Start of MSG
Rfid_ptr = 0 'Reset pointer
End If
Incr Rfid_ptr 'Move to next byte
Rfid_array(rfid_ptr) = Rfid_char 'Save char to array
If Rfid_ptr = 13 Then 'and correct length
Rfid_have_buffer = 1 'tell user space
Rfid_ptr = 0 'Reset buffer
End If
return
|
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
toto
|
Posted: Mon Sep 29, 2014 11:19 am Post subject: |
|
|
Hello i.dobson,
Thank You. I will test it and give feedback
Regards
toto |
|
Back to top |
|
|
protoncek
Joined: 16 May 2011 Posts: 52 Location: Slovenia
|
Posted: Mon Sep 29, 2014 3:50 pm Post subject: |
|
|
Ian, i guess this is for hardware UART.... if i would use software UART, i guess i would need to use pin change interrupt, right? Would this same routine work in that case? |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Sep 29, 2014 5:41 pm Post subject: |
|
|
Hi,
Sorry but I've not used a Software Serial Input. Using a pin Change Interrupt might work but every time a character is received the CPU will be blocked/stay in the ISR until the character is received.
You should use a Hardware UART when ever possible.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
protoncek
Joined: 16 May 2011 Posts: 52 Location: Slovenia
|
Posted: Mon Sep 29, 2014 5:48 pm Post subject: |
|
|
Sure, i understand. It's just that recently i needed more than one UART and since i used mega8, i've had no choice but to use SW one... And, you're right...in SW one CPU is indeed blocked for the time of receiving data, but since receiving data was the main thing, in my case this was acceptable...
Thanks! |
|
Back to top |
|
|
|