Sending values on UART (5282)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sending values on UART (5282)

1,561 Views
SVC2
Contributor II
Hi,
 
I am trying to design a communication protocol between the 5282 and a PC.

The 5282 sends characters from 0 to 0xFF and the PC is supposed to read them.
 
The problem I am having is reading the zeros! All other values (from 1 to 0xFF) work fine.
 
The code of the PC program is (in a while loop with timeouts):
       
Code:
unsigned char c;ReadFile(handle, &c, 1, &n_bytes_read, NULL);// read 1 character at a time

 
When the firmware sends a 0 integer, the ReadFile() function returns with n_bytes_read = 0.
 
So there is no way finding out if ReadFile() didn't read any value OR it read a 0 integer (which is the NULL character in ASCII).
 
I know that this is not a 5282 problem but rather a kernel32 but I thought someone might have solved this
issue.
 
Thanks,
S.
 
 
Labels (1)
0 Kudos
3 Replies

295 Views
ipa
Contributor III
Hi,
My idea: search Freescale for "Freemaster" - and  your problem is solved.
Regards,
ipa
0 Kudos

295 Views
RichTestardi
Senior Contributor II
So you're saying that Windows detects the nul character (since it causes ReadFile() to return), but doesn't pass it back to you (n_bytes_read is 0)?
 
This is just a shot in the dark, but is it possible you have software flow control enabled, and maybe set your xon/xoff characters to the nul character?
 
From the MS docs:
One other interesting note about software flow control is that reception of XON and XOFF characters causes pending read operations to complete with zero bytes read. The XON and XOFF characters cannot be read by the application, since they are not placed in the input buffer.
0 Kudos

295 Views
RichTestardi
Senior Contributor II
Or maybe better yet:
 
fNull: Specifies whether null bytes are discarded. If this member is TRUE, null bytes are discarded when received. 

See: http://msdn.microsoft.com/en-us/library/aa450503.aspx (Configuring a Serial Port )

0 Kudos