It appears that the parity bit is not being stripped off.
I cannot promise that the serial interface is correctly generating the parity bits for outgoing data, and I cannot promise that MATLAB is recognizing the 141 as being CR for line termination purposes.
If you subtract 128 from all of the values greater than 128, you get ER00<CR><LF>
I do not know whose fault it is that the parity is not being properly removed, but you have to deal with the aftermath.
As a work-around:
Change the terminator to LF because LF happens to have even parity anyhow.
Take all of the input lines and pass them through a translation routine that removes the parity. This could be as simple as
rmparity = @(S) char(S - (S>128)*128);
Take the resulting string and process it as a string, such as with sscanf() or as required.
For output, do not output anything directly. Instead, format it in to a string, such as with sprintf(), and pass the resulting string through a routine that adds parity. You can fwrite() the result.
The routine to add parity could do an array lookup: have a table with 128 entries, entry #K giving the even-parity version of char(K-1) . For even parity, that table is
evenparity7 = char((0:127)+128*mod(sum(dec2bin(0:127,7)-'0',2),2).');
makevenparity = @(S) evenparity7(S+1);
Best Answer