Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/23/04 08:34
Read: times


 
#81750 - 9th bit is supported
Responding to: ???'s previous message
hi,

The last time I tried it, it was impossible using the standard MS drivers & Windows API. This was because Windoze simply sets a "Parity Error" bit - but does not identify which specific character had the parity error.


Which API do you mean? We use 9-bit communication via _outp() and _inp(). COM port initialization looks like:
#define PORT	0x3F8
//...
	_outp(PORT+3, (128+32+8+2+1));		// 8 bit, 1 stop, parity always 1
	_outp(PORT+1, 0);			// baudrate
	_outp(PORT+0, 1);			//	115200
	_outp(PORT+3, (32+8+2+1));		// 8 bit, 1 stop, parity always 1  
//...
Our protocol uses syncronization bytes with 9th bit = 1 and data bytes with 9th bit = 0. To send it we use:
// send sync byte to COM port with 9th bit = 1
void SendSyncByte (unsigned char sync)
{
	while (! (_inp(PORT+5) & 32))
	{}					// wait till port ready
	_outp(PORT+3, (32+8+2+1));		// 8 bit, 1 stop, parity always 1
	_outp(PORT+0, sync);
}
// send data byte to COM port with 9th bit = 0
void SendDataByte (unsigned char data)
{
	while (! (_inp(PORT+5) & 32))
	{}					// wait till port ready
	_outp(PORT+3, (32+16+8+2+1));		// 8 bit, 1 stop, parity always 0
	_outp(PORT+0, data);
}
To receive and determine data/sync we use next:
// read from COM port
unsigned int ReadByte (unsigned int time_out)
{
	unsigned int data, timeout = time_out;
	unsigned char status;

	_outp(PORT+3, (32+8+2+1));		// 8 bit, 1 stop, parity always 1
	while (! ((status = _inp(PORT+5)) & 1))
	{
		if (! timeout--)
			return (0xFFFF);	// timeout
	}
	data = (unsigned int)_inp(PORT+0);
	if (status & 8)	return (0xFFFE);	// frame error
	if (!(status & 4)) data += 256;		// determine sync/data;
//						return data as 0...255
//						and sync as 256...511
	return (data);
}
This works at least for Win98. The only one restriction is that it is not possible to send/receive bytes simultaneously because parity control is modifyed depend on send/read. So only half-duplex mode used: PC sends to MCU sync+data then MCU answers with sync+data.

Regards,
Oleg

List of 23 messages in thread
TopicAuthorDate
Need help... MCU and PC communication            01/01/70 00:00      
   MCU & PC communication            01/01/70 00:00      
   I have the same problem            01/01/70 00:00      
   Need more help from this            01/01/70 00:00      
      I use ascii            01/01/70 00:00      
         Reply to Jose'            01/01/70 00:00      
   Fix the problem            01/01/70 00:00      
      To my helpers            01/01/70 00:00      
         Handshaking...            01/01/70 00:00      
         RETI            01/01/70 00:00      
   ascii ?            01/01/70 00:00      
   Handshaking and More !!            01/01/70 00:00      
      Delays            01/01/70 00:00      
         Thanks to all my helpers, problem solved            01/01/70 00:00      
         Delays            01/01/70 00:00      
            Delays            01/01/70 00:00      
               UART, mode 3            01/01/70 00:00      
                  The 9th bit is the parity for VB            01/01/70 00:00      
                     send data from mcu to pc            01/01/70 00:00      
                        Yes, but the 9th bit is the parity in VB            01/01/70 00:00      
                           9th bit lost by Windoze?            01/01/70 00:00      
                              9th bit is supported            01/01/70 00:00      
                                 32-bit MS Windows            01/01/70 00:00      

Back to Subject List