From d284d5a789c0d62d326f2a7f8942d02a0f2c33ea Mon Sep 17 00:00:00 2001 From: LiHuashen <854410664@qq.com> Date: Tue, 22 Jan 2019 19:26:53 +0800 Subject: [PATCH] updated COMMU --- docs/en/module/commu.md | 79 +++++++++++++++++++++++++++++++++++++- docs/zh_CN/module/commu.md | 2 +- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/docs/en/module/commu.md b/docs/en/module/commu.md index c6b74495..cb1988e2 100644 --- a/docs/en/module/commu.md +++ b/docs/en/module/commu.md @@ -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)** @@ -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. + + + +Copy [MCP_CAN_lib file](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Module/COMMU/Arduino/DependentLibrary/MCP_CAN_lib) to `C:\Users\\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 +#include +#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 +#include +#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); +``` + + + +#### RS485 communication + +This is a COMMU example for RS485 communication. + + + +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. + + \ No newline at end of file diff --git a/docs/zh_CN/module/commu.md b/docs/zh_CN/module/commu.md index 08247a98..dfb75962 100644 --- a/docs/zh_CN/module/commu.md +++ b/docs/zh_CN/module/commu.md @@ -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)**