If anyone knows C I could use a hand. I’m using a USART which needs to have an interrupt enabled so that when a packet is received it is taken to the correct memory buffer without the user program needing to call anything or poll. I previously bodged this working by adding extern variables in main.c, then creating them in the interrupt file:
I’m not a big fan of the bodge and need to create a single memory location that both the interrupt code and the user code can access. How can I do this?
Create the buffer in your interrupt file, every time the interrupt read data from the UART it does it store in there.
Create a function called something like buffer_read() into your interrupt file.
import the interrupt header in main.c and call the function buffer_read() when you need to read the buffer.
The best approach would be to have a different library that hold the buffer and exposes functions like read(), write(), delete() etc etc and both interrupt and main use the function to access to the bus.
Thanks for the help Andrea.
You’re right about the best approach using get() and put(), I can’t believe I didn’t think about that. I did what you said and created an extra header and source file, and the code compiled no problem. However, the compiler appears to be using the data buffer to store intermediate calculation numbers; even when I have the transmitter off, the receiver shows up as having data:
The receive should be all 0’s because at this point the transmitter is off.