http://qs321.pair.com?node_id=11131123


in reply to Re^3: How to read serial port with WIN32:SerialPort?
in thread How to read serial port with WIN32:SerialPort?

This 9th bit is generated internally by the UART based on the value of the parity bit. So, which parity bit is the Perl modules dealing with?

Perl does not do any parity, neither does any other language. The parity bit is generated and checked by the UART hardware. All that the OS and any language on top sees is a parity error if the check fails.

And do the modules allow this definition to be changed at will to drive the address function out onto the RS-485 bus?

That's an application of the mark and space "parity" bits. You could switch the serial format between "mark parity" and "space parity" to set or clear the parity bit from the application.

Of course it is possible to generate and verify the parity bit in the application, that's why some embedded U(S)ARTs allow 9 bit formats (8 bit plus application-specific use of the parity bit). On a generic PC-style USART, the data bits are limited to 8 bit, so if you want to use an application-specific parity bit, you are limited to 4 to 7 data bits.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re^4: How to read serial port with WIN32:SerialPort?

Replies are listed 'Best First'.
Re^5: How to read serial port with WIN32:SerialPort?
by jmlynesjr (Deacon) on Apr 15, 2021 at 00:19 UTC

    The MAX3140 datasheet description of 9bit mode:

    The MAX3140 supports a common multidrop communication technique refe +rred to as 9-bit mode. In this mode, the parity bit is set + to indicate a message that contains a header with a desti +nation address. Set the MAX3140’s parity mask to generate int +errupts for this condition. Operating a network in this mode + reduces the processing overhead of all nodes by enabling the + slave controllers to ignore most message traffic. This reliev +es the remote processor to handle more useful tasks.In 9-bit + mode, the MAX3140 is set up with eight bits plus parity. T +he parity bit in all normal messages is clear, but is set +in an address-type message. The MAX3140’s parity-interrupt mask g +enerates an interrupton high parity when enabled. When the mas +ter sends an address message with the parity bit set, all MAX3140 n +odes issue an interrupt. All nodes then retrieve the received b +yte to compare to their assigned address. Once addressed, the nod +e continues to process each received byte. If the node was not addr +essed, it ignores all message traffic until a new address is +sent out by the master.The parity/9th-bit interrupt is controlled onl +y by the data in the receive register and is not affected by data in +the FIFO, so the most effective use of the parity/9th-bitinte +rrupt is with FIFO disabled. With the FIFO disabled, received non-ad +dress words are ignored and not even read from the UART.

    The parity bit that this is referring to is a bit in an on-chip transmit control register. This register has to be modified to cause the chip generated parity bit to be set to indicate an address byte. And then be modified again to turn off address-mode.

    My guess is the Device::SerialPort module doesn't use it's parity argument for this purpose.

    James

    There's never enough time to do it right, but always enough time to do it over...

      The parity bit that this is referring to is a bit in an on-chip transmit control register. This register has to be modified to cause the chip generated parity bit to be set to indicate an address byte. And then be modified again to turn off address-mode.

      My guess is the Device::SerialPort module doesn't use it's parity argument for this purpose.

      Of course it does not. It becomes obvious when you read the POD of Device::SerialPort:

      parity

      One of the following: "none", "odd", "even".

      To use the parity bit for non-parity purposes, you would need other values, e.g. "mark" and "space" or simply "0" and "1".

      Also, parity() is one of the configuration parameter methods, not an operating method. It is not clear if changing the parity at operation time is supported:

      Some individual parameters (eg. baudrate) can be changed after the initialization is completed. These will be validated and will update the serial driver as required.

      Just to see an alternative implementation of a non-PC USART, here is a part of the documentation for the SERCOM peripheral of the Atmel/Microchip SAM D21 in USART Mode. It is also available in other SAMs, like the L21 and the D5x/E5x:

      USART Features

      • Full-duplex Operation
      • Asynchronous (with Clock Reconstruction) or Synchronous Operation
      • Internal or External Clock source for Asynchronous and Synchronous Operation
      • ...
      • Supports Serial Frames with 5, 6, 7, 8 or 9 Data bits and 1 or 2 Stop bits
      • Odd or Even Parity Generation and Parity Check
      • Selectable LSB- or MSB-first Data Transfer
      • ...

      Note that neither mark or space are supported for parity, but you can transfer 9 data bits. The data register is 16 bits wide to support using 9 data bits.

      If you want to drive people really mad, you use 9 bit mode with parity enabled and two stop bits. This ends with a line format of 13 bits (1 start + 9 data + 1 parity + 2 stop bits), and only a few other U(S)ARTs will be able to send or receive that format.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Alexander:

        Thanks for comfirming my guess. I have not gotten around to reading the POD or code.

        I have nothing else to add to this topic. It was a good discussion.

        James

        There's never enough time to do it right, but always enough time to do it over...