A FreeRTOS task-based wrapper for TWAI (Two-Wire Automotive Interface) CAN communication on ESP32-C6 microcontrollers.
This library provides a clean abstraction for handling TWAI/CAN bus communication using FreeRTOS tasks, enabling efficient, non-blocking communication in multi-threaded ESP32 applications.
- Task-Based Design: Runs TWAI communication in separate FreeRTOS task
- Non-Blocking: Doesn't block main application logic
- Thread-Safe: Proper synchronization for concurrent access
- Configurable: Flexible setup for different CAN bus configurations
- ESP32-C6 Optimized: Designed for ESP32-C6 microcontroller
Add to your platformio.ini:
lib_deps =
git@github.com:trailcurrentoss/Esp32C6TwaiTaskBasedLibrary.git@0.0.3- Clone or download this library
- Copy to your project's
lib/directory - Include in your sketch:
#include <TwaiTaskBased.h>#include <TwaiTaskBased.h>
void setup() {
Serial.begin(115200);
// Initialize TWAI with task-based handling
// (Configuration details in header file)
TwaiTaskBased::init();
}
void loop() {
// Your application code here
// TWAI communication runs in background task
delay(1000);
}See include/TwaiTaskBased.h for detailed configuration options including:
- CAN bus speed (250kbps, 500kbps, 1Mbps, etc.)
- GPIO pin assignments
- Task priority and stack size
- Filter settings
- ESP32-C6 microcontroller
- CAN transceiver module (SN65HVD230, etc.)
- Appropriate GPIO pins for TWAI TX/RX
MIT License - See LICENSE file for details
Improvements and contributions are welcome! Please submit issues or pull requests to the repository.