RMT, 1-Wire Slave and timing woes in general
Posted: Wed Aug 12, 2020 10:40 am
I have a project that requires me to emulate a simple 1-Wire Slave device.
HoHo, no problem pmckeon! I hear you say, just use https://github.com/orgua/OneWireHub
Except it's part of an existing project I've mostly completed in the native Espressif IDF and that library was made to work with the Arduino framework. I did try compiling it under the IDF tools but there were far too many compiler errors and warnings than I want to deal with right now in trying to port it over, plus it's a bit heavy for my needs anyway.
Fortunately 1-Wire protocol is relatively simple, the timing as I have discovered not so much.
I had something that sort of worked using a pin interrupt and high resolution timers but I found overheads of some functions and calls were causing me to miss the 60μs time-slot required by the Master device.
So, similar to the above library and it's initial discussion here:
viewtopic.php?t=3655
I'm trying to use the RMT peripheral and have setup a test case to read the 1-Wire bus but I either get an initial burst of random data or simply no data at all instead of the expected Reset pulse of about 480-500μs.
I have no idea if it's the way I've setup the RMT configuration or something else entirely.
HoHo, no problem pmckeon! I hear you say, just use https://github.com/orgua/OneWireHub
Except it's part of an existing project I've mostly completed in the native Espressif IDF and that library was made to work with the Arduino framework. I did try compiling it under the IDF tools but there were far too many compiler errors and warnings than I want to deal with right now in trying to port it over, plus it's a bit heavy for my needs anyway.
Fortunately 1-Wire protocol is relatively simple, the timing as I have discovered not so much.
I had something that sort of worked using a pin interrupt and high resolution timers but I found overheads of some functions and calls were causing me to miss the 60μs time-slot required by the Master device.
So, similar to the above library and it's initial discussion here:
viewtopic.php?t=3655
I'm trying to use the RMT peripheral and have setup a test case to read the 1-Wire bus but I either get an initial burst of random data or simply no data at all instead of the expected Reset pulse of about 480-500μs.
I have no idea if it's the way I've setup the RMT configuration or something else entirely.
Code: Select all
static void gun_owbrmt_task(void *pvParameter)
{
uint32_t length = 0;
RingbufHandle_t rb = NULL;
rmt_item32_t *items = NULL;
rmt_config_t rmt_conf;
rmt_conf.channel = RMT_CHANNEL_0;
rmt_conf.rmt_mode = RMT_MODE_RX;
rmt_conf.gpio_num = GPIO_OWBSLAVE_INPUT;
rmt_conf.mem_block_num = 1;
rmt_conf.flags = 0;
rmt_conf.clk_div = 80;
rmt_rx_config_t rx_conf;
rx_conf.filter_en = true;
rx_conf.filter_ticks_thresh = 30;
rx_conf.idle_threshold = 77;
rmt_conf.rx_config = rx_conf;
rmt_config(&rmt_conf);
rmt_driver_install(RMT_CHANNEL_0, 1000, 0);
rmt_get_ringbuf_handle(RMT_CHANNEL_0, &rb);
rmt_rx_start(RMT_CHANNEL_0, true);
while(rb)
{
items = (rmt_item32_t *) xRingbufferReceive(rb, &length, portMAX_DELAY);
length /= 4;
for(int i=0; i < length; i++)
{
ESP_LOGI(TAG, "[%d]Pulse (%d), [%d]Pulse (%d)\n", items[i].level0, items[i].duration0, items[i].level1, items[i].duration1);
}
vRingbufferReturnItem(rb, (void *) items);
}
ESP_LOGE(TAG, "gun_owbrmt_task quit unexpectedly!");
rmt_driver_uninstall(RMT_CHANNEL_0);
vTaskDelete(NULL);
}