MERG-DEV / CBUSESP8266

Implementation of Arduino CBUS library for ESP8266 + MCP2515
Other
0 stars 1 forks source link

Trouble getting this running on NodeMCU (ESP8266) #1

Open wormoworm opened 2 years ago

wormoworm commented 2 years ago

Hi,

I'm trying to get the CBUS_empty_ESP8266_test_v1 test working but I'm not having much success. I'm running it on a NodeMCU (ESP8266) board, with an MCP2515 connected via SPI.

I've imported the following libraries:

The first issue I encountered was that the ACAN2515 library (specifically ACAN2515.cpp) seems to be calling an SPI function that does not exist in the espressif8266 SPI library: image

Interestingly, the author of the ACAN2515 project states that ACAN2515 does not compile for ESP8266, so I'm a bit confused as to how CBUS8266 can use it as a dependency.

I commented out this missing function to try and get something running, and it after this, the project compiles. However, when it is run, it hangs at the CBUS.begin() call, and is consequently restarted by the watchdog after a few seconds:

> ** CBUS empty module for ESP8266 v1 ** main.cpp
> mode = FLiM, CANID = 1, NN = 13924
> code version = 1a beta 0
> compiled on Apr  1 2022 at 01:26:02, compiler ver = 201703
> © Duncan Greenwood (MERG M5767) 2020

******** EXECUTION HANGS HERE UNTIL WATCHDOG KICKS IN ********

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v00046c10
~ld

Is this behaviour something that you've seen before?

Thanks, Tom MERG M6113

obdevel commented 2 years ago

Hi Tom,

I've not looked at this library for some time. It was quickly hacked together for one member and to my knowledge it hasn't been used by anyone else. I think most people have moved on to ESP32, mainly because it so much more powerful for very little additional outlay.

The problem with the ESP8266 (and ESP32) is that any code that is called from an interrupt handler must be cached in RAM, as the processor can't access flash memory when handling an interrupt. The alternative is to explicitly poll for incoming messages.

I have an alternative CBUS library (CBUSMCP_CAN) that uses a different CAN bus library underneath. It's not ESP8266-specific but is generic enough to work ok.

I've attached a zip file which you'll need to extract into your libraries folder. This in turn depends on the MCP_CAN library which you'll also need to install (https://github.com/coryjfowler/MCP_CAN_lib).

You'll also need to use CBUS.begin(true)in your program to use polling instead of interrupts.

I've also attached an example which seems to compile ok here, but I don't have a board to test with. (You'll need to change to pin numbers in the defs.h file to match your setup).

Using polling instead of interrupts means that you may miss messages on a very busy bus. The polling is done by the CBUS.process() call in the loop() function.

Another problem you may encounter is that most CAN bus modules need 5V and the ESPs are 3.3V devices. Although the MCP2515 CAN controller chip will happily run at 3.3V, the CAN transceiver chip likely needs 5V. (The ESP32 has an onboard CAN controller so just needs an external 3.3V CAN transceiver, which can be picked up from eBay for a couple of quid).

The member who was using ESP8266 is Andrew Hicks and it may be worth dropping him a line as well to see where he got to.

Let me know how you get on.

Best wishes,

Duncan


From: Tom Homewood @.> Sent: 01 April 2022 09:37 To: MERG-DEV/CBUSESP8266 @.> Cc: Subscribed @.***> Subject: [MERG-DEV/CBUSESP8266] Trouble getting this running on NodeMCU (ESP8266) (Issue #1)

Hi,

I'm trying to get the CBUS_empty_ESP8266_test_v1 test working but I'm not having much success. I'm running it on a NodeMCU (ESP8266) board, with an MCP2515 connected via SPI.

I've imported the following libraries:

The first issue I encountered was that the ACAN2515 library (specifically ACAN2515.cpp) seems to be calling an SPI function that does not exist in the espressif8266 SPI library: [image]https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F4249537%2F161223728-12ed64f8-bad0-4e2a-bded-cd22cce4bc0b.png&data=04%7C01%7C%7C3fed445b7d8d495904fe08da13bad21b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637843990346073387%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=wgu8%2FDaUOzAl%2FfO9qD60qCXinDtsFmJeLT2LEui4VVc%3D&reserved=0

Interestingly, the author of the ACAN2515 project states that ACAN2515 does not compile for ESP8266https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpierremolinaro%2Facan2515%2Fissues%2F30&data=04%7C01%7C%7C3fed445b7d8d495904fe08da13bad21b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637843990346073387%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=PwOrUnYrHbhrXs3OxJmpX0oiNBWKTjvJkK4CNzuCNQ4%3D&reserved=0, so I'm a bit confused as to how CBUS8266 can use it as a dependency.

I commented out this missing function to try and get something running, and it after this, the project compiles. However, when it is run, it hangs at the CBUS.begin() call, and is consequently restarted by the watchdog after a few seconds:

CBUS empty module for ESP8266 v1 main.cpp

mode = FLiM, CANID = 1, NN = 13924

code version = 1a beta 0

compiled on Apr 1 2022 at 01:26:02, compiler ver = 201703

© Duncan Greenwood (MERG M5767) 2020

**** EXECUTION HANGS HERE UNTIL WATCHDOG KICKS IN ****

ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset

load 0x4010f000, len 3460, room 16

tail 4

chksum 0xcc

load 0x3fff20b8, len 40, room 4

tail 4

chksum 0xc9

csum 0xc9

v00046c10

~ld

Is this behaviour something that you've seen before?

Thanks, Tom MERG M6113

— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMERG-DEV%2FCBUSESP8266%2Fissues%2F1&data=04%7C01%7C%7C3fed445b7d8d495904fe08da13bad21b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637843990346229607%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=Yxxb3WLUkv6kBHbGqIjmNbM3Qcg8M2sh2Md1ICGyzlI%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADKBFH7WKIV5KI3KKMI7UYTVC2YTRANCNFSM5SH6W6TQ&data=04%7C01%7C%7C3fed445b7d8d495904fe08da13bad21b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637843990346229607%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=mkmiZwGZsak3lWZw0sup7xVVSJh7anUajSdU96tfaOw%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>

wormoworm commented 2 years ago

Hi Duncan, thanks for the quick reply.

Unfortunately I think GitHub stripped out your email attachments - I'll message you on the MERG forums with my email address if that's OK?

Your points about the 8266 being unsuitable for this task is noted - I do have some ESP32s lying around I could use, but I was curious as I saw this lib existed so I wanted to see what would happen!

With the CBUSESP32 library, is it possible to use another CAN controller? I have plenty of MP2515 boards lying around, but no transceivers on their own.

Thanks, Tom

obdevel commented 2 years ago

Hi Tom,

Yes, email me via the forum rather than messaging as I don't get on there often.

Whether a MCP2515 CAN module will work depends on the CAN transceiver chip it has. The common blue and yellow ones use a TJA1050 chip which I believe is 5V only and you can't split the power supply. It would be possible to interpose a level shifter on the CS, SCK, MISO and interrupt signals, which I believe is what Andrew did.

If you want to experiment with an ESP32, look on eBay for a module based on the SN65HVD230 chip.

D


From: Tom Homewood @.> Sent: 01 April 2022 17:23 To: MERG-DEV/CBUSESP8266 @.> Cc: obdevel @.>; Comment @.> Subject: Re: [MERG-DEV/CBUSESP8266] Trouble getting this running on NodeMCU (ESP8266) (Issue #1)

Hi Duncan, thanks for the quick reply.

Unfortunately I think GitHub stripped out your email attachments - I'll message you on the MERG forums with my email address if that's OK?

Your points about the 8266 being unsuitable for this task is noted - I do have some ESP32s lying around I could use, but I was curious as I saw this lib existed so I wanted to see what would happen!

With the CBUSESP32 library, is it possible to use another CAN controller? I have plenty of MP2515 boards lying around, but no transceivers on their own.

Thanks, Tom

— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMERG-DEV%2FCBUSESP8266%2Fissues%2F1%23issuecomment-1086110454&data=04%7C01%7C%7C141923e91cc94427682408da13fc0079%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637844270304253733%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=qLaO8fEQiSzEw46ILWfp6ACew%2FQ%2B1eN8UfhOUPV6zO8%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADKBFH26T2HZR4AW6ZTOVR3VC4PJJANCNFSM5SH6W6TQ&data=04%7C01%7C%7C141923e91cc94427682408da13fc0079%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637844270304253733%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=8JWglqyO70lNivkinVRAmKdmrcz7dy61aqPzLxfu5R4%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>