#automotive #lin #no-std #linbus

no-std mcp2003a

MCP2003A LIN transceiver driver with embedded-hal traits for no-std environments

23 releases

new 0.0.22 Nov 17, 2024
0.0.21 Nov 17, 2024
0.0.16 Oct 31, 2024
0.0.13 Jul 6, 2024
0.0.4 Jun 24, 2024

#218 in Embedded development

Download history 16/week @ 2024-07-29 35/week @ 2024-09-16 24/week @ 2024-09-23 6/week @ 2024-09-30 390/week @ 2024-10-28 96/week @ 2024-11-04 217/week @ 2024-11-11

703 downloads per month

MIT license

26KB
329 lines

mcp2003a

Embedded Rust Microchip MCP2003A/B LIN transceiver driver with embedded-hal traits for no-std environments.

Crates.io Documentation GitHub Repo

[!WARNING] This crate is still in development and may not be suitable for production use.

Full Documentation: https://docs.rs/mcp2003a/latest/mcp2003a/

Part Numbers

Tested on:

  • MCP2003A (No Longer Recommended for New Designs)
  • MCP2003E

Should also work with:

  • MCP2003B (functional drop-in replacement for MCP2003A)

References

Features

Uses embedded-hal digital traits for GPIO and embedded-hal-nb Serial traits for UART.

  • embedded-hal = "1.0.0" - Major breaking changes versus 0.2.x implementations.
  • embedded-hal-nb = "1.0.0" - Additional non-blocking traits using nb crate underneath.

Usage

Add the crate to your Cargo.toml:

cargo add mcp2003a

Example

let mut mcp2003a = Mcp2003a::new(uart2_driver, break_pin_driver, delay);

let lin_bus_config = LinBusConfig {
   speed: LinBusSpeed::Baud19200,
   break_duration: LinBreakDuration::Minimum13Bits, // Test for your application
   wakeup_duration: LinWakeupDuration::Minimum250Microseconds, // Test for your application
   read_device_response_timeout: LinReadDeviceResponseTimeout::DelayMilliseconds(15), // Test for your application
   inter_frame_space: LinInterFrameSpace::DelayMilliseconds(1), // Test for your application
};
mcp2003a.init(lin_bus_config);

mcp2003a.send_wakeup();

mc2003a.send_frame(0x01, &[0x02, 0x03], 0x05).unwrap();

let mut read_buffer = [0u8; 8]; // Initialize the buffer to the frame's known size
let checksum = mcp2003a.read_frame(0xC1, &mut read_buffer).unwrap();

Full Examples

(More coming soon)

  • ESP-32 via ESP-RS - Example using the MCP2003A with an ESP-32 microcontroller using the ESP-RS HAL.

Dependencies

~85KB