Hello All, I am working with interrupt based UART0, and I do have little problem in receiving data and storing it in array.
Here is the working ISR
void UART0ISR(void)__irq { if(U0IIR & RDA) { rxmessage=U0RBR; VICVectAddr = 0x00; } }
The problem is I will be receiving a sequence of Hex Data. For eg. 5A AA 06 at first. In this header the third byte 0x06 indicates the length of the characters that will be received further. Later.... I will be receiving 83 00 0A 01 00 01 . I am struggling to figure out and store these things in an array. None of the method I tried seemed to be useless. Can anyone please give some example or advise on it.
Warm Regards
What's the problem, exactly?
Do you know how to use arrays in 'C'?
Define a global array of the maximum length required.
eg: unsigned char rx_array[50];
A counter variable is needed to count the position in which the data will be written when the data will be received. The variable needs to be incremented by 1 after the data is written in that position. NOTE: This counter variable can be a local variable, but has to be 'static'. eg: static char rx_cntr=0;
Then the code becomes:
void UART0ISR(void)__irq { static char rx_cntr=0; if(U0IIR & RDA) { rx_array[rx_cntr++] = U0RBR; VICVectAddr = 0x00; } }
Have taught you to use array. Develop the logic of what you want to achieve exactly. [& send me the Tuition fees ;) ]
Read about the following topics ["GOOGLE Search"] static variables, local variables and global variables in C
... to consider what happens when you reach the end of the array?
Further reading: "Circular" or "Ring" buffers
The advantage with a proper circular buffer is that it has two indices - one owned by the ISR for inserting data. One owned by the main loop for reading data. So no locking is needed to protect these two indices, as long as the processor can read/write them atomically.
The world is full of code examples.
Just that the world expects people to have a working knowledge about Google and the other available search engines. Because they are so very much faster at producing an answer to most questions compared to forum threads.
The world is full of code examples. Just that the world expects people to have a working knowledge about Google and the other available search engines. Because they are so very much faster at producing an answer to most questions compared to forum threads.
Hi Can you please google and find me an example for what I am looking for. In the view of a beginner. To let you know, I am posting here after searching google first.
View all questions in Keil forum