Hi
I'm working on RS485 MAX485 communication from esp32s3 idf to silicon labs zigbee keypad(contains MAX3483 chip).
Connections:
keypad(MAX3483 ) -> TTL - RS485 Module
A -> A
B -> B
3.3V -> VCC
GND -> GND
TTL - RS485 Module -> ESP32-S3
DI -> GPIO-4
DE -> GPIO-42
RE -> GPIO-2
RO -> GPIO-5
If I make RE, DE to low at TTL-MAX485 side, I was able to read response given from MAX3483 chip.
when I try to send data from TTL-MAX485 to MAX3483 side, data reception is not happening at keypad
side.
Kindly check my configurations and let me know if any modifications required.
I'm working on RS485 MAX485 communication from esp32s3 idf to silicon labs zigbee keypad(contains MAX3483 chip).
Connections:
keypad(MAX3483 ) -> TTL - RS485 Module
A -> A
B -> B
3.3V -> VCC
GND -> GND
TTL - RS485 Module -> ESP32-S3
DI -> GPIO-4
DE -> GPIO-42
RE -> GPIO-2
RO -> GPIO-5
If I make RE, DE to low at TTL-MAX485 side, I was able to read response given from MAX3483 chip.
when I try to send data from TTL-MAX485 to MAX3483 side, data reception is not happening at keypad
Code:
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
#define TAG "RS485_APP"
#define UART_NUM UART_NUM_1 // Use UART1
#define TXD_PIN GPIO_NUM_4 // TX pin
#define RXD_PIN GPIO_NUM_5 // RX pin
#define BAUD_RATE 9600 // Baud rate
#define RS485_WRITE_PIN GPIO_NUM_42 // DE & RE pin (connected together)
#define RS485_READ_PIN GPIO_NUM_2 // DE & RE pin (connected together)
uint8_t rxBuff_from_device[254];
// Function declarations
void process_rs485_data(uint8_t *DeviceRxBuff, int len);
// UART initialization
// UART initialization
void init_uart() {
uart_config_t uart_config = {
.baud_rate = BAUD_RATE,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_driver_install(UART_NUM, 256, 256, 0, NULL, 0);
uart_param_config(UART_NUM, &uart_config);
uart_set_pin(UART_NUM, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
gpio_set_direction(RS485_WRITE_PIN, GPIO_MODE_OUTPUT);
gpio_set_direction(RS485_READ_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(RS485_WRITE_PIN, 1); // Default to RX mode
gpio_set_level(RS485_READ_PIN, 1);
}
// Receiving data task
void get_data_from_device(void *pvParameters) {
while (1) {
int len = uart_read_bytes(UART_NUM, rxBuff_from_device, sizeof(rxBuff_from_device), pdMS_TO_TICKS(70));
if (len > 0) {
printf("Raw Response and len %d: ", len);
for (int k = 0; k < len; k++) {
printf("%02X ", rxBuff_from_device[k]);
}
printf("\n");
}
// vTaskDelay(pdMS_TO_TICKS(1)); // Small delay
}
}
// Function to send RS485 data to devices
void send_rs485_to_device(uint8_t *data, size_t length) {
// gpio_set_level(RS485_ENABLE_PIN, 1); // Enable TX mode
// vTaskDelay(50 / portTICK_PERIOD_MS); // Ensure GPIO switch before sending
uart_write_bytes(UART_NUM, (const char *)data, length);
vTaskDelay(100 / portTICK_PERIOD_MS); // Allow transmission to complete
// gpio_set_level(RS485_ENABLE_PIN, 0); // Switch back to RX mode
// vTaskDelay(50 / portTICK_PERIOD_MS); // Allow some time before reading response
}
// // One-time task to send data
void periodic_send_task(void *pvParameters) {
uint8_t buftx[] = {0x84, 0xBA, 0x20, 0xFF, 0xFE, 0x92, 0x5E, 0x5F, 0x04, 0x01, 0x00, 0xB3, 0x11};
while(1){
ESP_LOGI(TAG, "Sending RS485 data once...");
send_rs485_to_device(buftx, sizeof(buftx));
// Optionally delay to allow UART to finish
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
// Delete this task after sending
// vTaskDelete(NULL);
}
void app_main(void) {
init_uart();
xTaskCreate(periodic_send_task, "periodic_send_task", 4096, NULL, 4, NULL);
// xTaskCreate(get_data_from_device, "get_data_from_device", 4096, NULL, 6, NULL);
}
Kindly check my configurations and let me know if any modifications required.
