mirror of
https://github.com/m5stack/m5-docs.git
synced 2026-05-20 10:23:01 -07:00
updated COMMU
This commit is contained in:
+78
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
***
|
||||
|
||||
:memo:**[Description](#Description)** 🛒**[Purchase](https://www.aliexpress.com/store/product/M5Stack-New-COMMU-Module-Extend-RS485-TTL-CAN-I2C-Port-with-MCP2515-TJA1051-SP3485-Development-Board/3226069_32954475633.html?spm=a2g1y.12024536.productList_5885013.subject_2)**
|
||||
:memo:**[Description](#Description)** :octocat:**[Example](#Example)** 🛒**[Purchase](https://www.aliexpress.com/store/product/M5Stack-New-COMMU-Module-Extend-RS485-TTL-CAN-I2C-Port-with-MCP2515-TJA1051-SP3485-Development-Board/3226069_32954475633.html?spm=a2g1y.12024536.productList_5885013.subject_2)**
|
||||
|
||||
<!-- :memo:**[Description](#Description)** :octocat:**[Example](#Example)** :electric_plug:**[Schematic](#Schematic)** 🛒**[Purchase](https://www.aliexpress.com/store/product/M5Stack-New-COMMU-Module-Extend-RS485-TTL-CAN-I2C-Port-with-MCP2515-TJA1051-SP3485-Development-Board/3226069_32954475633.html?spm=a2g1y.12024536.productList_5885013.subject_2)** -->
|
||||
|
||||
@@ -47,3 +47,80 @@ Be care about TTL Interface. It is a UART Interface actually by default. But you
|
||||
- **[Offical Video](https://www.youtube.com/channel/UCozgFVglWYQXbvTmGyS739w)**
|
||||
|
||||
- **[Forum](http://forum.m5stack.com/)**
|
||||
|
||||
## Example
|
||||
|
||||
### Arduino IDE
|
||||
|
||||
#### CAN communication
|
||||
|
||||
This is a COMMU example for CAN communication.
|
||||
|
||||
<!-- 这是两个COMMU模块分别堆叠了M5Core之后,相互之间收发数据的例程。 -->
|
||||
|
||||
Copy [MCP_CAN_lib file](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/COMMU/Arduino/DependentLibrary/MCP_CAN_lib) to `C:\Users\<user_name>\Documents\Arduino\libraries`, then open `commu_can_transmitter.ino`, `commu_can_receiver.ino` and burn to two M5Cores.
|
||||
|
||||
*The below code is incomplete(just for usage). If you want the complete code, please click [here](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/COMMU/Arduino/CAN).*
|
||||
|
||||
```arduino
|
||||
/*
|
||||
commu_can_transmitter.ino
|
||||
*/
|
||||
#include <M5Stack.h>
|
||||
#include <mcp_can.h>
|
||||
#include "m5_logo.h"
|
||||
|
||||
#define CAN0_INT 15 // Set INT to pin 2
|
||||
MCP_CAN CAN0(12); // Set CS to pin 10
|
||||
|
||||
// declaration
|
||||
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
|
||||
|
||||
// initialization
|
||||
M5.begin();
|
||||
CAN0.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ);
|
||||
/* Change to normal mode to allow messages tobe transmitted */
|
||||
CAN0.setMode(MCP_NORMAL);
|
||||
|
||||
// send data
|
||||
CAN0.sendMsgBuf(0x100, 0, 8, data);
|
||||
```
|
||||
|
||||
```arduino
|
||||
/*
|
||||
commu_can_receiver.ino
|
||||
*/
|
||||
#include <M5Stack.h>
|
||||
#include <mcp_can.h>
|
||||
#include "m5_logo.h"
|
||||
|
||||
#define CAN0_INT 15 // Set INT to pin 2
|
||||
MCP_CAN CAN0(12); // Set CS to pin 10
|
||||
|
||||
// declaration
|
||||
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
|
||||
|
||||
// initialization
|
||||
M5.begin();
|
||||
/* Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s */
|
||||
/* and the masks and filters disabled. */
|
||||
CAN0.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ);
|
||||
/* Set operation mode to normal so theMCP2515 sends acks to received data. */
|
||||
CAN0.setMode(MCP_NORMAL);
|
||||
pinMode(CAN0_INT, INPUT);// Configuring pin for /INT input
|
||||
|
||||
// read data
|
||||
CAN0.readMsgBuf(&rxId, &len, rxBuf);
|
||||
```
|
||||
|
||||
<img src="assets/img/product_pics/module/module_example/COMMU/example_module_commu_01.png" width="50%" height="50%">
|
||||
|
||||
#### RS485 communication
|
||||
|
||||
This is a COMMU example for RS485 communication.
|
||||
|
||||
<!-- 这是两个M5Core之间通过RS485相互收发数据的例程。 -->
|
||||
|
||||
Burn [example](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/COMMU/Arduino/RS485) to two M5Cores. Then after pressed Button A, this two cores will send message to each other and receive data.
|
||||
|
||||
<img src="assets/img/product_pics/module/module_example/COMMU/example_module_commu_02.png" width="50%" height="50%">
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
***
|
||||
|
||||
:memo:**[描述](#描述)** 🛒**[购买链接](https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-1172588093.64.6c2275f4nUJEfh&id=580999880340)**
|
||||
:memo:**[描述](#描述)** :octocat:**[例程](#例程)** 🛒**[购买链接](https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-1172588093.64.6c2275f4nUJEfh&id=580999880340)**
|
||||
|
||||
<!-- :memo:**[描述](#描述)** :octocat:**[例程](#例程)** :electric_plug:**[原理图](https://github.com/m5stack/M5-Schematic/blob/master/Modules/module_commu_sch.pdf)** 🛒**[购买链接](https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-1172588093.64.6c2275f4nUJEfh&id=580999880340)** -->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user