Skip to content

[UART] Add frame and parity error handling #341

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

Closed
wants to merge 9 commits into from

Conversation

Rocketct
Copy link
Contributor

@Rocketct Rocketct commented Aug 3, 2018

Introduced Frame Error check for the received byte

Introduced Frame Error check for the received byte
Copy link
Contributor

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rocketct I've left some comments.

Please also try to respect the code style of the source you are editing, for example:

  • spacing after assignment
  • if statements

What kinds of testing have you done with the changes? Are there any performance impacts?

@@ -91,8 +91,11 @@ void Uart::flush()
void Uart::IrqHandler()
{
if (sercom->availableDataUART()) {
rxBuffer.store_char(sercom->readDataUART());

sercom->isFrameErrorUART();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't do anything useful, just read the error and ignore.

Should we also clear the frame error?


sercom->isFrameErrorUART();
uint8_t c=sercom->readDataUART();
if( !sercom->isUARTError()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should also check the error type here, from the data sheet not all errors will have data associated with them.

This fix allow to avoid the error related to the issue arduino-libraries/ArduinoModbus#2,
 i had tested it using the example of ArduinoRS485 and ArduinoModbus library,
 this fix allow to receive alligned all packet sented to the board from the shield MKR 485,
 without this the percentage of the packet loosed was of the 50%.
uint8_t c=sercom->readDataUART();
if( !sercom->isUARTError()){
uint8_t c = sercom->readDataUART();
if (!sercom->isUARTError()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this condition is incorrect, please look at the data sheet again, not all error situations should result in us dropping the byte.

This fix allow to avoid the error related to the issue arduino-libraries/ArduinoModbus#2,
 i had tested it using the example of ArduinoRS485 and ArduinoModbus library,
 this fix allow to receive alligned all packet sented to the board from the shield MKR 485,
 as test i had use two boards with two mkr845 shield, one that blasting the other with pakcet,
 and the other that receive and show the byte received the sketch are the following:
 - receiver: https://github.com/bcmi-labs/ArduinoRS485/tree/master/examples/RS485Receiver;
 - Sender: https://github.com/bcmi-labs/ArduinoRS485/tree/master/examples/RS485Sender.
 the highest speed reachable was 500KHz that is unchangend respect the previous version.
@@ -135,6 +135,11 @@ bool SERCOM::isUARTError()
return sercom->USART.INTFLAG.bit.ERROR;
}

bool SERCOM:: isParityOrFrameError()
{
return sercom->USART.STATUS.bit.FERR | sercom->USART.STATUS.bit.PERR ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here i think we can optimize this by doing a single read of .reg instead of .bit and comparing the bit mask

@@ -164,6 +164,8 @@ class SERCOM
int writeDataUART(uint8_t data) ;
bool isUARTError() ;
void clearFrameErrorUART() ;
void clearParityErrorUART() ;
bool isParityOrFrameError();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick: extra space here

} else {
sercom->readDataUART();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a comment above this live, saying read and discard the data, as it's invalid

if (sercom->isFrameErrorUART()) {
sercom->clearFrameErrorUART();
}
if (sercom->isFrameErrorUART()) {
sercom->clearFrameErrorUART();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some weird spacing here? tabs vs spaces?

Rocketct and others added 3 commits August 10, 2018 18:30
minor fix in Uart library
minor spacing
update comments
@sandeepmistry sandeepmistry changed the title Fix first Stop bit zero [UART] Add frame and parity error handling Aug 10, 2018
@sandeepmistry sandeepmistry requested a review from cmaglie August 10, 2018 16:42
@sandeepmistry
Copy link
Contributor

@cmaglie can we please try to get this in before the next SAMD core release. Let me know if you have any comments.

more spacing
sercom->clearFrameErrorUART();
}

if (sercom->isFrameErrorUART()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block should check for parity error, not frame error again.

@sandeepmistry
Copy link
Contributor

Closing in favour of #349.

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

Successfully merging this pull request may close these issues.

2 participants