-
-
Notifications
You must be signed in to change notification settings - Fork 253
CAN running at half speed #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
MCP or internal ESP32 can controler? |
If MCP, does the frequency of the quartz on the board match the parameters in the code? |
Sorry I left that information out, I am using the ESP32's internal CAN controller |
switch (baudRate) {
/* maybe check theese registers in the ESP32 refrence manual. TWAI Bus. I dont have any issuses what so ever. (arduino IDE) |
@Petros144 Thank you for pointing me to the registers, I will have a good look at this and revert back. |
I added :
To ESP32SJA1000.cpp at line 126 |
@kp911, how about adding it at line 72 or 133 instead, then it will be disabled for all baud rates ? But I think I am missing something else here. |
@NeliusNDL @sandeepmistry This discussion just gave me an idea. Two years ago I found that ESP32 is not able to communicate in low bandwidth (under 50kbps) due to the clock frequency and the baud rate prescaler is limited in 6 bits. Following the thread about the hardware limitation (https://esp32.com/viewtopic.php?t=2142) just recently I read that in Rev2 or up versions of the chip they changed the meaning of bit 4 in IER, from "Wake-up interrupt" to "divide BRP by 2". That explains why the CAN ran in half speed (for some reason bit 4 was set) in newer ESP32. I modified the code again in order to support this change. However, I don't have a v2+ chip at hand and it would take quite a few weeks to order. So if someone could kindly test my code I'd create a PR that makes either slower bandwidth possible and finally support CANOpen standard with ESP32, too; or workaround this "bug" or "new feature" in ESP32 chip for once and all. I'll create the PR soon. Please test it if your time permits. I tested all speeds from 1000kbps until 50kbps with my v1 chip, in real life scenario, I connected my ESP + VP230 to an Android Nano + MCP2515 (+TJA1050), I can't go lower of course due to the limitations in my chip. |
@mister0wl I will gladly test. I have old and new versions of the ESP32, please send me a link to your modified code or post it here (or PM me) |
@NeliusNDL Sounds great! :) I created pull request #71 but you can also clone from here: https://github.com/mister0wl/arduino-CAN |
Hey @NeliusNDL , did you find the time to test the code with v2 chip? I could've been ordered one for myself in the meantime but it seems Chinese merchants don't know what they sell as they could not give me the info if their chip is v2 or not. sigh So you're our hope. ;-) |
@mister0wl I did do some tests. All working very well. In addition I have made some more changes. CAN bus testing and finalization is on my to-do list for mid to end june. Will post my results here when all done with a copy of my changes |
Hi, Hardi |
Hi, what baudrates did you try? |
Hi, |
In ESP32SJA1000.cpp, there's I suppose the calculated BTR0 and BTR1 values go on the 'value' field, as the mask field is always the same for all baudrates. For instance, using this calculator and parameters 80Mhz, 33.33kbps, I get BTR0= 138 and BTR1= 28. Using
or
I'm measuring a 112kbps signal. I asked somewhere else, and some person provided me with the 4 timing bit parameters to connect to 33.33kbps GMLAN and they were these: Using the TWAI driver I did measure a 33.33kbps signal. I need to translate those values to BTR0 and BTR1 values. After some trial and error I found these register values, using the default modifyRegister(REG_BTR1, 0x0f, 0x0c): Using chatgpt and providing it the 4 parameteres + 80MHz input clock frequency: BTR0= 0x3e, BTR1 = 0x77. modifyRegister(REG_BTR1, 0x77, 0x0c); Still need to try in my car... |
For some reason around about the time I switched to an RTOS system I have to call CAN.begin(1000E3) to get it to work at 500kbs.
Does anyone have any idea why ?
Where could the clock speeds have been incorrectly defined (and what clock ?)
The text was updated successfully, but these errors were encountered: