Hi,
I am trying to read the RS485 Absolute encoder from EK-TM4C129. I am using the MAX485 module to convert RS485 to ttl, which is half duplex, where DE is Active high, and RE is active low. I have written the code to enable the Transmitter and receiver, where needed. we must transmit the data ID to receive the position and extract it, as mentioned in the snapshot of the datasheet. The problem is that there is no data receiving When I go step over in my main() code composer, I find it stuck at the function " receive data(); "which means the send query(0x02) function is successfully executed, but I have set the variable query in the expression to see if it changes from 0x00 to 0x02, it doesn't. I don't understand where's the problem. I have attached the code,

Code:
Moderator edit: added code tags.
I am trying to read the RS485 Absolute encoder from EK-TM4C129. I am using the MAX485 module to convert RS485 to ttl, which is half duplex, where DE is Active high, and RE is active low. I have written the code to enable the Transmitter and receiver, where needed. we must transmit the data ID to receive the position and extract it, as mentioned in the snapshot of the datasheet. The problem is that there is no data receiving When I go step over in my main() code composer, I find it stuck at the function " receive data(); "which means the send query(0x02) function is successfully executed, but I have set the variable query in the expression to see if it changes from 0x00 to 0x02, it doesn't. I don't understand where's the problem. I have attached the code,

Code:
C:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/uart.h"
#define BAUD_RATE 2500000 // 2.5 Mbps
uint32_t averageValue;
uint8_t query;
uint32_t receivedValue = 0;
double angle;
int temp=0;
uint32_t position_Value = 0;
void GPIOInit(void) {
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_6 | GPIO_PIN_7);
}
void EnableTransmit(void) {
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_PIN_6);
}
void EnableReceive(void) {
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_PIN_7);
}
void UARTInit(void) {
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);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), BAUD_RATE,
UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE);
}
void sendQuery(query) {
//query = 0x8A; // Data ID code
UARTCharPut(UART0_BASE, query);
}
uint32_t receiveData(void) {
uint8_t receivedByte;
uint8_t i;
while (!UARTCharsAvail(UART0_BASE)) {
} // Wait until data is available
// Receive bytes for AS0, AS1, and AS2
for (i = 0; i < 3; i++) {
receivedByte = UARTCharGet(UART0_BASE);
receivedValue = (receivedValue << 8) | receivedByte;
}
// Extract valid 21 bits from AS2
uint32_t as2 = receivedValue & 0x1FFFFF;
// Combine AS0, AS1, and AS2
receivedValue = (as2 << 14) | (receivedValue >> 21);
return receivedValue;
}
int main(void) {
uint8_t i;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
temp=1;
GPIOInit();
temp=2;
UARTInit();
temp=3;
while (1) {
for (i = 0; i < 10; i++) {
EnableTransmit();
temp=4;// Enable transmission (DE high, RE low)
sendQuery(0x02);
temp=5;
SysCtlDelay(40); // Delay for 40 microseconds
}
EnableReceive();
temp=6;// Enable reception (DE low, RE high)
receiveData();
temp=7;// Receive and process data
SysCtlDelay(40);
// Delay for 40 microseconds
// for ( i = 0; i < 10; i++) {
position_Value += receiveData();
SysCtlDelay(40); // Delay for 40 microseconds
// }
// Calculate the average accumulated value
averageValue = position_Value / 10;
// Convert the average value to an angle using the 19-bit resolution
double angle = (double)averageValue * (double)(2^19) / 360.0;
// Handle further processing or actions based on the angle
// For example, print the angle value or use it in your application
SysCtlDelay(SysCtlClockGet() / 2); // Delay before the next iteration
}
}