Heh, I have similar problem! Newe needet to sovle thi on PIC, but one I made core for ATmega48.
The idea:
I made buffer structure in memory something like this:
type rs232Rxbuffer:
dim stateflags as byte
' bit 0 irqgotchatacter flag indicating that there was irq an we need to update buffer
' bit 1 canrecivenextcharacter flag indicating that we can receive next character on next rs232 irq
dim maxlen as byte
dim pointer as byte
dim data as byte*maxlen
end type
not the algorythm:
what is protocol for your rs232 receiver?
I had following idea:
packet len 4 bytes (allways).
byte 1 ='[' packet begin character
byte 2 = data
byte 3 = data
byte 4 =']' packet end chatacter
so my buffer was 16 bytes long (plus header declarations)
when I got character, te RxD interrupts occure in this interrupt I white character to my buffer in pointer location and set flag irqgotchatacter on. this flag mean that main buffer service routine should update buffer data and prepare buffer for next chatacter.
there is some pseido code:
on rs323 goto rs232hadler
call bufferhadler
main:
goto main
END PROGRAM
sub rs232handler
if flag (rs232buffer.stateflags.canrecivenextcharacter) is on then
write character from buffer to memory address what found in rs232buffer.pointer
set flag (rs232buffer.stateflags.irqgotcharacter) on 'info to handler than we must update buffer
set flag (rs232buffer.stateflags.canreceivenextcharacter) off 'to disable receive next character while handler not proseed buffer update
end if
end sub
sub bufferhadler
if flag (rs232buffer.stateflags.irqgotcharacter) is on then 'check if we must proseed buffer update
inceremet rs232.pointer
if rs232buffer.pointer is more than rs232buffer.maxlen then
set pointer to data begin
end if
set flag (rs232buffer.stateflags.canrecivenextcharacter) on 'clear flag to indicate that irq can prseed on next character from rs232 port
end if
end sub
something like this dould be done with multiply characters on receive.
there also should be added par where bufferhadler analyze data and make decision when to overwrite old data in buffer. i used 16 byte buffer(plus header data) for 4 byte packets.
if you plan to use this idea for GPS NMEA data proceed I recommend max buffer size at least two times of theoretically longest NMEA message.
this is not only solution for multiply characte receiving. also usually this is done on AVR with C programming language, but i never tried this, because I don't know C in general.
I hope tha you get an idea for this...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
in this code bufferhandler should do ll thing an least 2 times of baud rate. it is not recomended to use wai 1 ms ir similar commands for delays or you can get problems with receive to buffer stuff...
for delay i recommend to read post about RPM measurement with 16f628. there is good delay solution with timer.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
how can you send values to be stored in the memory over serial and have them be used in the program as varibles that can be updated on the fly?
Heh, I have similar problem! Newe needet to sovle thi on PIC, but one I made core for ATmega48.
The idea:
I made buffer structure in memory something like this:
type rs232Rxbuffer:
dim stateflags as byte
' bit 0 irqgotchatacter flag indicating that there was irq an we need to update buffer
' bit 1 canrecivenextcharacter flag indicating that we can receive next character on next rs232 irq
dim maxlen as byte
dim pointer as byte
dim data as byte*maxlen
end type
not the algorythm:
what is protocol for your rs232 receiver?
I had following idea:
packet len 4 bytes (allways).
byte 1 ='[' packet begin character
byte 2 = data
byte 3 = data
byte 4 =']' packet end chatacter
so my buffer was 16 bytes long (plus header declarations)
when I got character, te RxD interrupts occure in this interrupt I white character to my buffer in pointer location and set flag irqgotchatacter on. this flag mean that main buffer service routine should update buffer data and prepare buffer for next chatacter.
there is some pseido code:
on rs323 goto rs232hadler
call bufferhadler
main:
goto main
END PROGRAM
sub rs232handler
if flag (rs232buffer.stateflags.canrecivenextcharacter) is on then
write character from buffer to memory address what found in rs232buffer.pointer
set flag (rs232buffer.stateflags.irqgotcharacter) on 'info to handler than we must update buffer
set flag (rs232buffer.stateflags.canreceivenextcharacter) off 'to disable receive next character while handler not proseed buffer update
end if
end sub
sub bufferhadler
if flag (rs232buffer.stateflags.irqgotcharacter) is on then 'check if we must proseed buffer update
inceremet rs232.pointer
if rs232buffer.pointer is more than rs232buffer.maxlen then
set pointer to data begin
end if
set flag (rs232buffer.stateflags.canrecivenextcharacter) on 'clear flag to indicate that irq can prseed on next character from rs232 port
end if
end sub
something like this dould be done with multiply characters on receive.
there also should be added par where bufferhadler analyze data and make decision when to overwrite old data in buffer. i used 16 byte buffer(plus header data) for 4 byte packets.
if you plan to use this idea for GPS NMEA data proceed I recommend max buffer size at least two times of theoretically longest NMEA message.
this is not only solution for multiply characte receiving. also usually this is done on AVR with C programming language, but i never tried this, because I don't know C in general.
I hope tha you get an idea for this...
in this code bufferhandler should do ll thing an least 2 times of baud rate. it is not recomended to use wai 1 ms ir similar commands for delays or you can get problems with receive to buffer stuff...
for delay i recommend to read post about RPM measurement with 16f628. there is good delay solution with timer.