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); } }