This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C1294XL: Transmit and Receive RS485 data from encoder

Part Number: EK-TM4C1294XL

I am trying to read data from RS485 absolute Encoder with 2.5MBps(ecoder20) with my EK-TM4C1294 kit(The encoder requires transmitting Data ID) , I have to read the data and then send to a BLDC driver which only accept SPI , so will then need to send using SPI.
Firstly, CAn I use differential pins of TM4C1294 for this purpose?
Currently I am using Max485 module to convetrt the data into UART, but didn't get the data.(The code is attached)

Secondly, is it possible to recieve the data from encoder at 2.5MBPS, and then send to driver in SPI.


Regards,

Muzammil

#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c1294ncpdt.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"

#define DE_PIN GPIO_PIN_2
#define RE_PIN GPIO_PIN_3

void initUART(void)
{
  // Initialize the UART.
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  GPIOPinConfigure(GPIO_PA0_U0RX);
  GPIOPinConfigure(GPIO_PA1_U0TX);
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

}

void transmitAndReceive(uint8_t data) {
    // Set DE and RE pins for transmit mode
    GPIOPinWrite(GPIO_PORTE_BASE, DE_PIN | RE_PIN, DE_PIN);

    // Transmit data
    UARTCharPut(UART0_BASE, data);

    // Wait for transmission to complete
    while (UARTBusy(UART0_BASE)) {
    }

    // Set DE and RE pins for receive mode
    GPIOPinWrite(GPIO_PORTE_BASE, DE_PIN | RE_PIN, RE_PIN);

    // Wait for incoming data
    while (!UARTCharsAvail(UART0_BASE)) {
    }

    // Receive and process received data
    char receivedChar = UARTCharGet(UART0_BASE);

    // Process receivedChar as needed
    // For example, print it or perform further processing
}

int main(void) {
    // Initialize the system clock to run at 120 MHz
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ);

    initUART();

    while (1) {
        // Transmit 0x02 and receive encoder value
        transmitAndReceive(0x02);

        // Transmit 0x8A and receive encoder value
        transmitAndReceive(0x8A);
    }
}

  • Hi,

    Firstly, CAn I use differential pins of TM4C1294 for this purpose?

    All the pins that can be for UART TX and RX are listed in the datasheet. You can use different pins as long as they are listed in the datasheet for UART. 

    Secondly, is it possible to recieve the data from encoder at 2.5MBPS

    Shouldn't be a problem from MCU hardware point of view. SPI can operate up to 60Mhz. UART can operate up to 7.5Mbps in regular mode. 

  • Thanks Charles, this information confirms that the controller is all set for this conversion, but  My code is not working, the data is not transmitted.

  • Hi,

      You need to use SysCtlClockFreqSet() to configure the system clock for TM4C129 MCU, not SysCtlClockSet(). SysCtlClockSet() is only for TM4C123 MCU. 

    Please refer to the TivaWare hello example on how to configure the system clock for Tm4C129. 

    For TM4C129 MCU, you would configure the clock like below example. 


    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN |
    SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_240), 120000000);