hello everyone,
I'm trying to implement a circular buffer, but my problem is really with interrupts in general.
How can I write to a variable that is then read by an interrupt-handling function?
I've attached the serial interrupt to a buffering function, and it autamatically reads in whatever is on the line as soon as it's received. What I want to do is change the point at which the buffer circles around by assigning to it with other code in the class (which contains the handler).
The code I have now simply doesn't perform the assignment, the handler recirculates the buffer at the value that was assigned before the handler was attached.
My code:
private:
void FillSerialBuffer();
public:
MS3DMGX2(PinName tx, PinName rx);
volatile unsigned char Buffer[87];
volatile unsigned char BufferEnd;
volatile unsigned char BufferLength;
void Mode(unsigned char Selection);
MS3DMGX2::MS3DMGX2(PinName tx, PinName rx) : DataLines(tx, rx), LED(LED1),
BufferEnd(0), BufferLength(31)
{
DataLines.baud(115200);
DataLines.format(8, Serial::None, 1);
DataLines.attach(this, &MS3DMGX2::FillSerialBuffer, Serial::RxIrq);
}
void MS3DMGX2::Mode()
{
BufferLegnth = 86;
}
void MS3DMGX2::FillSerialBuffer()
{
while (DataLines.readable())
{
Buffer[BufferEnd] = DataLines.getc();
BufferEnd++;
BufferEnd %= BufferLength;
}
}
hello everyone,
I'm trying to implement a circular buffer, but my problem is really with interrupts in general.
How can I write to a variable that is then read by an interrupt-handling function?
I've attached the serial interrupt to a buffering function, and it autamatically reads in whatever is on the line as soon as it's received. What I want to do is change the point at which the buffer circles around by assigning to it with other code in the class (which contains the handler).
The code I have now simply doesn't perform the assignment, the handler recirculates the buffer at the value that was assigned before the handler was attached.
My code: