0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32のtwai(CAN)で特定のCAN IDのみ受信する

Last updated at Posted at 2025-01-06

ESP32を使って1Mbpsで流れているバスを全部拾うときついので、自分の必要なIDだけHW側でフィルタする。
使っているマイコンはESP32-C6だけど他のシリーズでも同じはず。

例)0x03Aのスタンダードフレームのみ読むとき

twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(PIN_CANTX, PIN_CANRX, TWAI_MODE_NORMAL);
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_1MBITS();
twai_filter_config_t f_config;
f_config.acceptance_code = (0x03A << 21);
f_config.acceptance_mask = ~(0x1FF << 21);
f_config.single_filter = true;
twai_driver_install(&g_config, &t_config, &f_config);
twai_start();

解説

公式

image.png

image.png

図の一番右がビットの並びの一番左。
なので、acceptance_codeで03AのIDをセットして、acceptance_maskで(図の)左のほうをマスクする。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?