6 Replies Latest reply on Jun 27, 2020 3:59 AM by LePo_1062026

    Which component to use for UART with 32 databits

    OzTa_1570606

      Hi,

       

      I wanted to get advise on which component to use with a datagram as shown below? UART component shows 8 (default) up to 9 data bits. And in the advanced tab for the TX buffer and RX buffer default is set to 4 bytes.

       

      How should one configure the UART component for the this datagram?

       

      uart.JPG

       

      Thanks for the help!

      Oz

        • 1. Re: Which component to use for UART with 32 databits
          MoTa_728816

          Hi,

           

          As the description states "any microcontroller UART",

          I "hope" that it will not require special method to send a byte.

           

          So if we can assume that all we need to send is 8 bytes of data array,

          I think that something like below will work. (I'd use "UART" for this.)

          Note: Needless to say, values for reg_address, data, crc must be prepared before used.

          ====================

              CyGlobalIntEnable; /* Enable global interrupts. */

            

              UART_Start() ;

           

              uint8_t buf[8] ; 

              uint8_t sync_reserved = 0xA0 ;

              uint8_t slave_address = 0 ;

              uint8_t reg_address ;

              uint32_t data ;

              uint32_t crc ;

            

              buf[0] = sync_reserved ;

              buf[1] = slave_address ;

              buf[2] = (reg_address << 1) + 0x01 ;

              buf[3] = (data >> 24) & 0xFF ;

              buf[4] = (data >> 16) & 0xFF ;

              buf[5] = (data >>  8) & 0xFF ;

              buf[6] = data & 0xFF ;

              buf[7] = crc ;

            

              UART_PutArray(buf, 8) ;

          ====================

           

          moto

          1 of 1 people found this helpful
          • 2. Re: Which component to use for UART with 32 databits
            LePo_1062026

            Oz,

             

            Although a UART can be designed to go beyond 9 bits it's not really a good idea unless both sides of the comm are clocking their UARTs using a crystal.  This is because the UART is not self-clocking.  For an 8-bit data size up to a 4% difference between UART clocks before data errors occur.  The start and stop bits of the UART protocol are used to resync the receiving UART to the sending UART.   If the data size is increased, the clock difference error adds up.

             

            The datasheet snip you included is informing you that in this protocol up to 64 bits are transmitted.  However they assume that the UART comm is at 8 bits times up to 8 bytes.  Your app has to take care of the assembly and disassembly of the packet.

             

            The Rx and Tx buffers are 4 bytes by default because this is the size of the Rx and Tx FIFOs.  However you can set either the Rx or Tx (or both) buffers to larger sizes.  When you do that, the component driver will allocate the buffer in RAM and enable the respective interrupt to move the incoming data into the Rx buffer and transmitting data from the Tx buffer.

             

            moto's example above uses the PutArray() API call to move the packet data from the Tx buffer to the UART.

             

            Len

            1 of 1 people found this helpful
            • 3. Re: Which component to use for UART with 32 databits
              OzTa_1570606

              Thanks Tanaka-san! That is very helpful!

              • 4. Re: Which component to use for UART with 32 databits
                OzTa_1570606

                Thanks Len!

                 

                TMC2208 datasheet indicates that the driver will synch itself to MCU's clock. However, this may not mean it is the same thing as using an external clock.

                 

                But, the driver allows for a clock input to be used, and if I have issues I could use an external crystal to be used by both PSOC5LP and driver.

                 

                I am still working on it. Once I get it done. I will share the project bundle as well as some pictures showing the actual setup.

                 

                Thanks!

                • 5. Re: Which component to use for UART with 32 databits
                  MoTa_728816

                  Dear OzTa-san,

                   

                  If I remember correctly, UART protocol has "start bit" and "stop bit" which also work as sync timing.

                  So as far as both device's clock accuracy is within 2%, they should be OK to communicate.

                   

                  Although PSoC and FPGA can easily introduce other protocols,

                  usual MCU would stick with the standard UART protocol,

                  so IMHO, we can assume that the device takes advantage of this sync feature of UART.

                   

                  This is why I wrote

                  > As the description states "any microcontroller UART",

                  > I "hope" that it will not require special method to send a byte.

                   

                  Best Regards,

                  27-Jun-2020

                  Motoo Tanaka

                  • 6. Re: Which component to use for UART with 32 databits
                    LePo_1062026

                    OzTa_1570606,

                    TMC2208 datasheet indicates that the driver will synch itself to MCU's clock. However, this may not mean it is the same thing as using an external clock.

                    In a UART-style protocol, the start and stop bits are used to resync the next byte.

                     

                    If you notice that the first 4 bits of the packet are "1010" (called the Sync).  These bits allow the slave device to perform a pulse width measurement of the bit width.  This allows the slave to determine the data rate and therefore adjust the clock on the slave to match the clock on the master as best as possible.  This is how the TMC2208 "auto-bauds" (synchs) to the master clock.   This is common on other packet protocols such as LIN.

                    But, the driver allows for a clock input to be used, and if I have issues I could use an external crystal to be used by both PSOC5LP and driver.

                    Since the TMC2208 is a stepper motor controller you might need a external crystal to make sure the pulse timing for the steps have very low accumulated error.  If external clocking is needed, I recommend that you place the external crystal on the PSoC5 then create a 10 MHz to 16 MHz output from the PSoC5 to feed the CLK input of the TMC2208.  This will provide the accuracy you may need for the TMC2208 step pulses and will guarantee that the data rates between the PSoC5 and the TMC2208 will be very minimized and in-sync.

                     

                    Len