Created
April 10, 2020 18:01
-
-
Save benpeoples/9d364999d2e43dd94b7b4c333bcbf461 to your computer and use it in GitHub Desktop.
ESP32 DMX transmitting task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DMX1_IO (0) | |
#define DMX1_TX (16) | |
#define DMX1_RX (32) | |
#define BUF_SIZE (512) | |
uint8_t data[513]; // This is a global in this case | |
/* | |
So this is an incredibly simple transmit-only DMX task for ESP32 ESP-IDF V4 | |
1. Why the magic number (0x1 << 5) in the inverse? | |
V4.0 and V4.1 are renaming various constants. (0x1 << 5) inverts the TX line and avoids the BS around renamed constants. | |
2. WTF are you inverting the line? | |
UART is idle-high. BREAK is a 172us LOW pulse. | |
I could flip this to a GPIO and do the same thing, but inverting the TX pin seemed cleaner and faster. | |
3. Why is the BREAK 300us? | |
Made it more reliable than 172, inverting seems to take a while if other things are happening. | |
*/ | |
static void dmx_writer_uart1(void *ignore) | |
{ | |
uint8_t start_code = 0x00; | |
const int uart_num = UART_NUM_1; | |
uart_config_t uart_config = { | |
.baud_rate = 250000, | |
.data_bits = UART_DATA_8_BITS, | |
.parity = UART_PARITY_DISABLE, | |
.stop_bits = UART_STOP_BITS_2, | |
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, | |
}; | |
/* DMX RX/TX control - HIGH = talking */ | |
gpio_pad_select_gpio(DMX1_IO); | |
gpio_set_direction(DMX1_IO,GPIO_MODE_OUTPUT); | |
gpio_set_level(DMX1_IO, 1); | |
//Configure UART1 parameters | |
uart_param_config(uart_num, &uart_config); | |
uart_set_pin(uart_num, DMX1_TX, DMX1_RX, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); | |
uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0); | |
for(;;) | |
{ | |
uart_wait_tx_done(uart_num,1000); // Wait for done | |
uart_set_line_inverse(uart_num, (0x1 << 5)); // Set BREAK | |
ets_delay_us(300); // Wait 176us | |
uart_set_line_inverse(uart_num, 0); // Set MAB | |
ets_delay_us(25); // Wait 12us | |
uart_write_bytes(uart_num, (const char*) &start_code, 1); // Send NSC | |
uart_write_bytes(uart_num, (const char*) data+1, 512); // Send universe | |
} | |
vTaskDelete(NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment