If im not wrong, an ISR is supposed to do minimal processing when it receives a data serially(via UART). Im planning on implementing such a protocol for communication between 2 systems via uart. This is a rough situation of how i plan on coding the ISR. Assume 2 system A & B where A is sending a message to B: Keyword is used to indicate start of message(Established-data/length cannot be the keyword). ChannelOK,Length of data,RxLength,RxData,Packet received flag in B's process are default 0.Length of data=no. of(all data)in bytes(ex:if all data=1,Length of data=1)
A's Process
Send Keyword
Send Length of data
Send all data
B's Process
Rx Interrupt
enter ISR
ISR: if(Received Byte == Keyword && !ChannelOK)
{
Set ChannelOK
}
if(ChannelOK && RxLength)
{
Set Length of data=received byte
ChannelOK=0
RxLength=0
}
if(Length of data != 0 && RxData)
{
Store Data
--Length of data
if(Length of data==0)
{
Set Packet received flag
RxData=0
}
}
if(ChannelOK)
{
Set RxLength
}
if(Length of data)
{
Set RxData
}
Reset to Interrupt Again
My doubt is: B has so many stuff to do in the ISR while A is sending continuously. Asumming A sends data at 7.5Mbps(11 bits per transfer), the ISR has to reset the interrupt ever (11/7.5M) seconds. This seems very very small. Will data be lost if i fail to reset the interrupt on time or will it be stored in the 16 byte FIFO so that an interrupt can be immediately triggered the second i reset the interrupt or must i slow down A Tx process by waiting for an ACK for each byte(slows down a lot)???
Im a newbie to ISR's.Please do help Any ISR designs or protocols for serial data communication would be useful
Thanks
Answer
I will propose a method that you may find helpful with some modification to suit your needs.
In this method the ISR is so small , it only saves data in an array for later decoding in the main program , two counters are used to detect of received data and decoded data. offcourse you can use pointer instead of the counters.
ISR:
{
Receivedbytes[i++]= Rxbuffer;
dataReceived++;
}
main:
void UARTdecode{
if (dataDecoded {
Received byte = Receivedbytes[j++];
///// where routine
if(Received Byte == Keyword && !ChannelOK)
{
Set ChannelOK
}
..
..
..
//// end of routine
dataDecoded+=x; (where x is the amount of data decoded or message length)
}
}
P.S:It is VERY IMPORTANT that i and j are declared as Static variables
You can also check arduino hardware serial library source code , it is open source and it uses ISR to receive data "HardwareSerial.h" in the installation directory
No comments:
Post a Comment