This software accompanies the application note AN15146 Tamagawa T-format Encoder Master Interface using FlexIO on MCXA366, which describes a FlexIO-based T-format master implemented on the FRDM-MCXA366. The project transmits the request byte stream (TXD), holds the RS-485 driver-enable signal (DIR) for exactly the request duration, captures the encoder response (RXD), validates the returned frame, and then publishes position, encoder ID, temperature and status.
The target encoder is a Tamagawa TS5700N8501: 17-bit single-turn absolute data (ABS), 16-bit multi-turn data (ABM), 2.5 Mbps asynchronous differential NRZ communication. Position is read with the DID3 full-position transaction (CF = 0x1A), which returns ABS, encoder ID, ABM, ALMC and SF in an 11-byte response. The bit rate is fixed at 2.5 Mbps inside the driver and derived from the 90 MHz FlexIO root clock, so the rate is changed through the clock configuration rather than through a baud-rate parameter. The supplied example uses polling transfers.
- FlexIO0 drives TXD on D17, samples RXD on D18, and controls the external RS-485 DE/DIR line on D16.
- One TX shifter, one RX shifter and three timers implement transmit, receive and direction control.
- DID3 (CF = 0x1A) returns ABS, ENCID, ABM, ALMC, SF and CRC8 in a single 11-byte response.
- The parser checks the echoed CF and the CRC8, masks ABS to 17 bits, sign-extends ABM from 16 bits, and reports whether the multi-turn count can be trusted.
- ALMC and SF are decoded bit by bit, so a communication alarm cannot hide a concurrent encoder error (over-speed, counter overflow, over-heat, multi-turn error, battery error, battery alarm).
- Encoder ID and encoder temperature are read through the EEPROM transactions.
- Optional reset transactions are provided: error reset (ID7, CF = 0xBA) and multi-turn plus error reset (IDC, CF = 0x62). The start-up reset is disabled by default and enabled with the
T_FORMAT_RESET_ERRORS_AT_STARTUPmacro insource/t-format_polling_transfer.c. - Polling transfers use bounded retry loops and restore the FlexIO state after a timeout.
- MCUXpresso IDE V25.6 or later
- SDK_26_09_00_FRDM-MCXA366
- MCUXpresso for Visual Studio Code: This example supports MCUXpresso for Visual Studio Code, for more information about how to use Visual Studio Code please refer here.
- FRDM-MCXA366
- Tamagawa T-format encoder (TS5700N8501)
- RS-485 transceiver module with direction control (for example MAX485 or SN65HVD series)
- Encoder power supply (5 V) and, for multi-turn operation, a VBAT backup supply
- USB Type-C cable
- Personal Computer
-
Connect the T-format encoder to the FRDM-MCXA366 through the RS-485 transceiver according to the pin mapping table below. The pads listed are the MCXA366 logic side of the interface: TXD and RXD reach the encoder as the single differential SD/DS pair, while DIR is a board-local transceiver direction control and is not an encoder cable signal. Do not connect the MCU pins directly to the encoder differential pair.
Project
SignalFlexIO
SignalMCXA366
PadDirection Purpose DIR FLEXIO0_D16 P2_8 Output RS-485
drive/receive controlTXD FLEXIO0_D17 P2_9 Output Request
data to encoderRXD FLEXIO0_D18 P2_10 Input Encoder
response dataGND - GND Reference Common
logic ground -
Connect the FRDM-MCXA366 to the computer via a USB Type-C cable. The hardware setup is shown below:
-
Open MCUXpresso IDE, in the Quick Start Panel, choose Import from Application Code Hub.
-
Enter the demo name in the search bar.
-
Click Copy GitHub link, MCUXpresso IDE will automatically retrieve project attributes, then click Next>.
-
Select main branch and then click Next>, Select the MCUXpresso project, click Finish button to complete import.
- Compile the project and download it to FRDM-MCXA366 board.
- Open serial port assistant, set baud rate to 115200, connect to FRDM-MCXA366 debug UART port.
- Press the reset button on FRDM-MCXA366 to begin operation, then observe the real-time encoder position values via UART.
- The serial assistant connected to the FRDM-MCXA366 serial port will display the result below.
Multi-turn datais the signed revolution count from ABM, andsingle-turn datais the position within one revolution, spanning 0 to 131071 (2^17 - 1). A new line is printed on significant shaft motion, on a change of the status flags, or once per second.
Encoder T-format example
FlexIO Root Clock is 90 MHz
[T-format] Encoder ID: 0x11
Logic-OR of Over-heat, Multi-turn error, Battery error and Battery alarm
[T-format] Multi-turn data: 1, single-turn data: 66765
Logic-OR of Over-heat, Multi-turn error, Battery error and Battery alarm
[T-format] Temperature: 34
[1.00s] Encoder ID: 0x11
Multi-turn data: 1, single-turn data: 66765
Temperature: 34
[2.00s] Encoder ID: 0x11
Multi-turn data: 1, single-turn data: 66765
Temperature: 34
- The
Logic-OR ...line is the encoder's own latched hardware status reported through the SF byte, not a software error, and is typically a battery alarm on a unit powered off without a VBAT backup supply. To clear it, keep the shaft stationary with the backup supply present and build once withT_FORMAT_RESET_ERRORS_AT_STARTUPset to 1 insource/t-format_polling_transfer.c. This uses the IDC transaction, which also zeroes the multi-turn count and so redefines the multi-turn reference at the current shaft position.
Questions regarding the content/correctness of this example can be entered as Issues within this GitHub repository.
Note: For more general technical questions regarding NXP Microcontrollers and the difference in expected functionality, enter your questions on the NXP Community Forum
| Version | Description / Update | Date |
|---|---|---|
| 1.0 | Initial release on Application Code Hub | September 21th 2026 |