B4R Question CAN bus for ESP32 by rCAN

peacemaker

Expert
Licensed User
Longtime User
HI, All

I'm tired trying to make CAN bus by ESP8266...
Two ESP32 modules are received at last, and trying again :)

It looks like the ready lib for ESP32 is https://www.b4x.com/android/forum/threads/rcan-library.120832/.
Question about pinout, circuit diagram and the lib initialization:
B4X:
can.Initialize("can_DataAvailable", 53, 0, can.SPEED_500KBPS)

What ESP32 pins better to use (not occupied during boot) for CAN bus and what are their number for init ?
1622197676995.png


Lib's example code is with 53 and 0, but ... what is 53 pin ?
1622197788694.png

If to look at this pinout, and choose, say, GPIO16 (receiving from MCP2515 TX pin) and GPIO17 (transmitting to MCP2515 RX pin) - init should be like:
B4X:
can.Initialize("can_DataAvailable", 16, 17, can.SPEED_500KBPS)
?
 

peacemaker

Expert
Licensed User
Longtime User
Solved.
If to solder so: GPIO17 to RX of the CAN-adapter, GPIO16 to TX of the CAN-adapter
PCA82C250

Clipboard01.jpg

and initialize so:
B4X:
can.Initialize("can_DataAvailable", 17, 16, can.SPEED_100KBPS)

sending and receivig by CAN bus works !
Clipboard02.jpg

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Private can As CAN
    Private tim As Timer
    'Private pin As Pin
    Private JustStarted As Boolean = True
    #if Sender
    Public MyAddr As Int = 1
    #else
    Public MyAddr As Int = 2
    #End If
    Public Count As Long
    Public bc As ByteConverter
End Sub

Private Sub AppStart
    Serial1.Initialize(256000)
    Log(CRLF, "AppStart....wait for 3 sec")
    Delay(3000)
    Log(can.Initialize("can_DataAvailable", 17, 16, can.SPEED_100KBPS))
   
    #if Sender
    tim.Initialize("tim_Tick",1000)
    tim.Enabled=True
    #end if
End Sub

Sub can_DataAvailable(Data() As Byte)
    Log("I (", MyAddr, ") received from ID: ", can.MessageId, ": ", Data)
End Sub

Sub tim_Tick
    If JustStarted Then
        Dim m() As Byte = "Start"
        can.SendMessageExtended(MyAddr, m)
        JustStarted=False
    Else
        Dim d() As Byte = bc.StringToBytes(Count)
        Log("Sending from ", MyAddr, ": ", d)
        can.SendMessage(MyAddr, d)
        Count = Count + 1
    End If
End Sub
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
And it seems to me that it works due to the MCU has built-in CAN-controller, and externally just CAN-transceiver IC (with UART-port) is needed.
But MCP25215 IC is such CAN-controller with SPI-port that is on the board together with second IC - the CAN-transceiver TJA1050 IC (with UART-port).

And it looks like that this fact is the reason why ESP8266 cannot work with CAN-bus simply.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Here the main question that what pins\functions are provided by B4R libraries, and setup all for this
 
Upvote 0
Top