3 Replies Latest reply on May 6, 2019 4:09 AM by BragadeeshV_41

    UART_CTRL_MARK

    ROTH_3708891

      I have a project where we are producing new "Remote" boards. We are using RS485 half duplex. The Master commands are always sent with a 1 set as the 9th bit (Mark).
      The Remote UART (that I'm trying to set up) should completely ignore any data word that does not have a 1 as the 9th bit (Mark parity). This way each of the multiple remote boards will ignore any communications from the other remotes.

      Only if the 9th bit is a 1 will the UART listen to the rest of the word. The rest of the word is the master command and the remote address. If the address matches the remote's address, set by DIP Switch, the remote processes the command.

      Master word = 1yyyyxxxx, 1= 9th bit (Mark), yyyy =command (ie- 0100 = send buffered data), xxxx = remote address

       

      RX

      What do I use to have the UART look for the 1 in the 9th bit (mark) and ignore anything that is not a 1?

       

      TX

      I'm trying to understand how to control the Mark / Space parity bit before transmitting the data. If I'm reading correctly UART_CTRL_MARK, "Configures whether the parity bit during the next transaction (in Mark/Space parity mode) will be a 1 or 0."

      I don't seem to understand the formatting. It looks like I should use UART_WriteControlRegister(UART_CTRL_MARK). How do I tell complete this and say whether I want the bit to be a 1 or a 0? Do I need to check the API control enable box in the UART configuration?

       

      I'm just starting to learn a little C programming. I need basic detailed help from those smarter than I!! This is my first work with PSoC. I would welcome examples!

      Right now I'm using the full duplex UART example program to try to understand how everything works. RS232 from my PC characters typed are echoing back to the PC. (115200 baud, 9 data bits, Mark / Space Parity, 1 stop bit, no flow) Notice that I'm transmitting the data twice. My intentions are to transmit one with the Mark parity set and one with Space parity set just so I can look on the scope and make sure I can see it working. I don't seem to know how to control the Mark/Space bit. Once I have this figured out, I can move on to the task above.

       

      CY_ISR(RxIsr)

      {

          uint8 rxStatus;        

          uint8 rxData;          

         

          do

          {

              /* Read receiver status register */

              rxStatus = UART_RXSTATUS_REG;

       

              if((rxStatus & (UART_RX_STS_BREAK      | UART_RX_STS_PAR_ERROR |

                              UART_RX_STS_STOP_ERROR | UART_RX_STS_OVERRUN)) != 0u)

              {

                  /* ERROR handling. */

                  errorStatus |= rxStatus & ( UART_RX_STS_BREAK      | UART_RX_STS_PAR_ERROR |

                                              UART_RX_STS_STOP_ERROR | UART_RX_STS_OVERRUN);

              }

             

              if((rxStatus & UART_RX_STS_FIFO_NOTEMPTY) != 0u)

              {

                  /* Read data from the RX data register */

                  rxData = UART_RXDATA_REG;

                  if(errorStatus == 0u)

                  {

                      /* Send data backward */

                     UART_WriteControlRegister(UART_CTRL_MARK);

                     UART_TXDATA_REG = rxData;

                      UART_TXDATA_REG = rxData;

                  }

              }

          }while((rxStatus & UART_RX_STS_FIFO_NOTEMPTY) != 0u);

        • 1. Re: UART_CTRL_MARK
          BragadeeshV_41

          Hi ROTH_3708891,

           

          Check the API control enable box in the UART configuration and use UART_TX_SetTxAddressMode(UART_TX_SET_MARK) to set the parity bit to mark/ space.

          Note: All the bytes after the address byte will be sent with a space unless cleared using UART_TX_SetTxAddressMode (UART_TX_SET_SPACE)

           

          Generate an interrupt every time an address is detected (parity bit is MARK). Check RX - On Address detect in the Advanced tab of the configuration window.

          In the ISR, you can use the UART_RX_STS_MRKSPC bit of the status register to know whether the received data is address or data. This bit is set if MARK is received. You can use this logic in your code.

           

          Sample Code:

           

          CY_ISR(receiveISR)

          {

                  uint8 rxData;

           

                  if( UART_RX_STS_MRKSPC & UART_TX_ReadRxStatus())

                  {

                      rxData = UART_ReadRxData();

                      UART_PutString("Mark -Accepted\r\n");

                      UART_PutChar(rxData);

                      /*Your processing*/

                  }

          }

           

          int main(void)

          {

              CyGlobalIntEnable; /* Enable global interrupts. */

           

              RX_ISR_StartEx(receiveISR);

              UART_Start();

              UART_SetTxAddressMode(UART_TX_SET_MARK);

             

              UART_PutChar(CMD_BYTE);

              UART_PutString("UART TEST\r");

              UART_SetTxAddressMode(UART_TX_SET_SPACE);

          }

           

          I've used a full duplex communication in this case. Refer to the device datasheet that has a sample source code to implement in half duplex.  Let us know in case you need further help.

           

          Regards,

          Bragadeesh

          • 2. Re: UART_CTRL_MARK
            ROTH_3708891

            Thanks Bragadeesh,

             

            I was off yesterday. I'll work on this over the next couple of days. I'm

            sure I'll have more questions.

             

            James

            • 3. Re: UART_CTRL_MARK
              BragadeeshV_41

              Hi ROTH_3708891.,

               

              Please let us know if the sample code worked as per your requirement.

               

              Regards,

              Bragadeesh