Skip to content

Serial Flush blocks forever but not only at programm start #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
WMuellSika opened this issue Aug 31, 2022 · 1 comment
Open

Serial Flush blocks forever but not only at programm start #678

WMuellSika opened this issue Aug 31, 2022 · 1 comment

Comments

@WMuellSika
Copy link

Hi there

I have a similar issue to #597, but not at the start of my program.

In my code, there is a function which looks like this:

void SlaveWaterCOM::send() {

    digitalWrite(2, HIGH);

    Serial1.write(outbuffer.dataarray, 28);
    
    Serial1.flush();

    digitalWrite(2, LOW);
}

The function communicates via the Serial1 over a MAX3075, and therefore it needs an enablepin for the driver.

In my program, this is the only point I use the Serial1.write or the Serial1.flush command.

Sadly, the program sometimes hangs at the Serial. Flush() command.

I tracked the issue down to the Sercom->USART.INTFLAG.bit.TXC flag, which seems to never be written.

Has anyone a clue why this could be?

@Duality4Y
Copy link

Duality4Y commented Dec 30, 2024

I have this exact same issue, it hangs on communication using a sercom module when calling flush() at some point,
I ALSO see with a debugger that the TXC bit is NOT set.
(JLink + gdb )

But In my specific case it seems to also be related to putting the SAMD to sleep, as when I disable this functionality it seems to run fine and stable.

It doesn't happen on the first wake-up and sleep cycle but somewhere down the road at some Time X
But that is in my case.

Here is an observation I made in my case the serial communication is with a modem,
I saw It had transmitted an A and it was about to transmit an T,
This was AT as it is a modem command it makes sense, what doesn't really make sense to me is where it went wrong,
the previous line was a println containing something like "AT+COPS" but somewhere between A and T the TXC bit was cleared from the interupt enable register and caused the following flush to hang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants