About the CAN controller.

Hans Dorn
Posts: 62
Joined: Tue Feb 21, 2017 2:21 am

Re: About the CAN controller.

Postby Hans Dorn » Sat Mar 25, 2017 6:14 pm

Heh, I read that one a while ago.

Problem is, some hardware vendors require RTR's if you want to communicate with their equipment.

Guess they failed to read the linked post :)

RTR's are a nuisance.


Cheers

ThomasB
Posts: 38
Joined: Sun Dec 25, 2016 12:11 am

Re: About the CAN controller.

Postby ThomasB » Sun Mar 26, 2017 2:21 am

Howdy.

Wow, a lot of conversation going on here.
I just merged your PR rudi.
Yeah... RTR is still a thing and some guys asking for extended format frames. Shouldn't be a big deal to integrate this.

Anyhow... I am still in Asia and only can occasionally check the forum.

Regards
Thomas

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: About the CAN controller.

Postby jcsbanks » Tue Mar 28, 2017 8:22 pm

Great work on this! Great device!

Received my ESP32 today and trying to compile CAN example.

I thought it was best to clone version 0.1_third_parts and the menuconfig includes the options and saves them correctly.

I copied main.c from http://www.barth-dev.de/wp-content/uplo ... N_demo.zip over the template I was using, cleaned and did a make. I did not include component.ml from the demo because it referenced identical files that were already in version 0.1_third_parts.

I do not know what to do about CAN_config.c in the demo because it appears to duplicate entries in the menuconfig but with slightly different names. When I try to compile without CAN_config.c, the linker has an undefined reference to CAN_cfg which is defined in the file I am missing. If I do not use version 0.1_third_parts I cannot see where to set the transmit CAN ID.

Code: Select all

#include "CAN_config.h"

CAN_device_t CAN_cfg = {
	.speed=CAN_SPEED_1000KBPS,		// CAN Node baudrade
	.tx_pin_id = GPIO_NUM_5,		// CAN TX pin
	.rx_pin_id = GPIO_NUM_4,		// CAN RX pin
	.rx_queue=NULL,					// FreeRTOS queue for RX frames
};
I am new to Github and Linux based tools/build environment, so probably missing the point, but am I trying to merge a demo that is not compatible with the fork?

I might try just removing version 0.1_third_parts and trying the demo as it is and see if I can find the CAN trasmit ID.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: About the CAN controller.

Postby jcsbanks » Tue Mar 28, 2017 8:42 pm

As a follow up, the demo compiles fine if I compile it as it is in the zip, so I've removed version 0.1_third_parts. I can also see that I could:

Code: Select all

CAN_frame_t __TX_frame;
...and then set the ID with:

Code: Select all

__TX_frame.MsgId
Which is quite useful as I want to transmit and receive on multiple CAN IDs.

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: About the CAN controller.

Postby rudi ;-) » Wed Mar 29, 2017 9:21 am

@jcsbanks

the http://www.barth-dev.de/wp-content/uplo ... N_demo.zip is all
- demo
- driver

so if you take this like it is, then you can compile and start CAN project.

if you want use the drv folder for next project
you copy this structure in your next project and set in cfg/CAN_config.c your setup for CAN manually.


but if you want to use a general CAN Driver pack with menuconfig and ESP-IDF structure
( this was the goal to do the things with it )
then you can use the version 0.1_third_parts, that include the driver pack and menuconfig structure
like in ESP-IDF.

if you want to "install" / use for next can driver project the CAN Driver Pack by setting over menuconfig
then you take the version 0.1_third_parts component pack like you have try
to clone version 0.1_third_parts and the menuconfig includes the options and saves them correctly.
and build your own CAN project code
or you can take the demo code and must change things for include, component.mk in it to point to component/can instead to the included drv folder, thats normal :) .....

btw you can copy this CAN component in your ESP-IDF
under components, then you have allways this CAN Driver Pack available.
this is the sense of the driver pack with menuconfig
adapted to the component structure of esp-idf

and sure
you can copy this in the project folder
instead of esp-idf components folder
If you do not want to have it in esp-idf
and you have then this structure
yourProject ->
yourProject -> Makefile
yourProject -> main
yourProject -> main -> myAPP.c
yourProject -> main -> component.mk
yourProject -> components
yourProject -> components -> can
yourProject -> components -> can -> CAN.c
yourProject -> components -> can -> kconfig
yourProject -> components -> can -> component.mk
yourProject -> components -> can -> include
yourProject -> components -> can -> include -> CAN.h
yourProject -> components -> can -> include -> CAN_config.h
yourProject -> components -> can -> include -> CAN_regdef.h
and if you cpy the driver pack to your ESP-IDF components folder
you need only this in your project
yourProject ->
yourProject -> Makefile
yourProject -> main
yourProject -> main -> myAPP.c
yourProject -> main -> component.mk
and use in the myAPP.c

Code: Select all

#include "CAN.h"
#include "CAN_config.h"
thats all.

make menuconfig
makes then the sdkconfig file and config file for the project.

if you did your step, you have now config vars like this:

Code: Select all

menuconfig config defines that you can use in the code:
 *				ESPCan activated:
 *					- CONFIG_ESPCAN ( bool ) 
 * 				baudrade 100,125, 250, 500, 800, 1000 and user: 
 *					- CONFIG_CAN_SPEED_100KBPS 
 *					- CONFIG_CAN_SPEED_125KBPS
 *					- CONFIG_CAN_SPEED_250KBPS
 *					- CONFIG_CAN_SPEED_500KBPS
 *					- CONFIG_CAN_SPEED_800KBPS
 *					- CONFIG_CAN_SPEED_1000KBPS
 *					- CONFIG_CAN_SPEED_USER_KBPS
 *				user can speed
 *					- CONFIG_CAN_SPEED_USER_KBPS ( bool )
 *						- CONFIG_CAN_SPEED_USER_KBPS_VAL (value)
 *				gpio pins for CANRx and CANTx
 *					- CONFIG_ESP_CAN_RXD_PIN_NUM
 *					- CONFIG_ESP_CAN_TXD_PIN_NUM 
 *				node id ( CAN identifier )
 *					- CONFIG_ESP_CAN_NODE_ITSELF
 *				enbable/disable send test frames
 *					- CONFIG_CAN_TEST_SENDING_ENABLED
 *					- CONFIG_CAN_TEST_SENDING_DISABLED 

and you can use this in your "own" code in a new project


if you want use the demo code and the Driver Pack with menuconfig
then you can delete the drv folder in the demo project ( is replaced with components/can from Driver Pack with menuconfig )
the component.mk file then looks like this then in the main

Code: Select all

#
# Main component makefile.
#
# This Makefile can be left empty. By default, it will take the sources in the 
# src/ directory, compile them and link them into lib(subdirectory_name).a 
# in the build directory. This behaviour is entirely configurable,
# please read the ESP-IDF documents if you need to do this.
#
empty.

now you can use in your main.c code like this:

inlcudes

Code: Select all

#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"

#include "CAN.h"
#include "CAN_config.h"
you can use the CAN Speed Config Define from menuconfig like this

Code: Select all


#ifndef CONFIG_ESPCAN
 #error for this demo you must enable and configure ESPCan in menuconfig
 #endif

#ifdef CONFIG_CAN_SPEED_100KBPS 
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_100KBPS 
#endif

#ifdef CONFIG_CAN_SPEED_125KBPS 
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_125KBPS 
#endif

#ifdef CONFIG_CAN_SPEED_250KBPS 
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_250KBPS 
#endif

#ifdef CONFIG_CAN_SPEED_500KBPS 
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_500KBPS 
#endif

#ifdef CONFIG_CAN_SPEED_800KBPS 
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_800KBPS 
#endif

#ifdef CONFIG_CAN_SPEED_1000KBPS 
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_1000KBPS 
#endif

#ifdef CONFIG_CAN_SPEED_USER_KBPS
#define CONFIG_SELECTED_CAN_SPEED CONFIG_CAN_SPEED_USER_KBPS_VAL /* per menuconfig */
#endif

now you can work with the define var
CONFIG_SELECTED_CAN_SPEED
CONFIG_ESP_CAN_TXD_PIN_NUM
CONFIG_ESP_CAN_RXD_PIN_NUM

like this ( this is a replacement for CAN_config.c and not more need )

Code: Select all


/* brief: rudi
 * over menuconfig you can set the cfg
 * defines are used in the head of code then
 * if you change to user cfg
 * you can change here too by your self
 * how you need this.
*/
CAN_device_t CAN_cfg = {
	.speed		= CONFIG_SELECTED_CAN_SPEED,	// CAN Node baudrade
	.tx_pin_id 	= CONFIG_ESP_CAN_TXD_PIN_NUM,	// CAN TX pin example menuconfif GPIO_NUM_5
	.rx_pin_id 	= CONFIG_ESP_CAN_RXD_PIN_NUM,	// CAN RX pin example menuconfig GPIO_NUM_4
	.rx_queue	= NULL,							// FreeRTOS queue for RX frames
};


a test frame send looks like this
and you can use the menuconfig defined var
CONFIG_ESP_CAN_NODE_ITSELF
for your CAN node unit ID itself

Code: Select all


void task_CAN_TX(void* pvParameters) {

   CAN_frame_t __TX_frame;
   uint32_t counter = 0;

      __TX_frame.MsgID = CONFIG_ESP_CAN_NODE_ITSELF;
      __TX_frame.DLC   =  8;
      __TX_frame.data.u8[0] = 'E';
      __TX_frame.data.u8[1] = 'S';
      __TX_frame.data.u8[2] = 'P';
      __TX_frame.data.u8[3] = '-';
      __TX_frame.data.u8[4] = 'C';
      __TX_frame.data.u8[5] = 'A';
      __TX_frame.data.u8[6] = 'N';
      __TX_frame.data.u8[7] = counter;

while(1) {
      __TX_frame.data.u8[7] = counter;
      CAN_write_frame(&__TX_frame);
      vTaskDelay( 1000 / portTICK_PERIOD_MS);  // to see ( printf on receiver side ) what happend..
      counter++;
      if (counter >= 256) counter = 0;
  }
}
and you can ( not must ) use for this example then the menuconfig define var
CONFIG_CAN_TEST_SENDING_ENABLED
like this

Code: Select all


#ifdef CONFIG_CAN_TEST_SENDING_ENABLED
		vTaskDelay( 1000 / portTICK_PERIOD_MS);
		xTaskCreate(&task_CAN_TX, "task_CAN_TX", 2048, NULL, 5, NULL);
		#endif

an example code looks then like this

Code: Select all


#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"


#include "CAN.h"
#include "CAN_config.h"

/* brief: rudi
 * you can use menuconfig for this
 * and you can expand like you need
 * you can also use your own
 * cfg - look in the main/cfg folder
 * you have then change by self
 */
 #ifndef CONFIG_ESPCAN
 #error for this demo you must enable and configure ESPCan in menuconfig
 #endif

#ifdef CONFIG_CAN_SPEED_100KBPS
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_100KBPS
#endif

#ifdef CONFIG_CAN_SPEED_125KBPS
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_125KBPS
#endif

#ifdef CONFIG_CAN_SPEED_250KBPS
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_250KBPS
#endif

#ifdef CONFIG_CAN_SPEED_500KBPS
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_500KBPS
#endif

#ifdef CONFIG_CAN_SPEED_800KBPS
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_800KBPS
#endif

#ifdef CONFIG_CAN_SPEED_1000KBPS
#define CONFIG_SELECTED_CAN_SPEED CAN_SPEED_1000KBPS
#endif

#ifdef CONFIG_CAN_SPEED_USER_KBPS
#define CONFIG_SELECTED_CAN_SPEED CONFIG_CAN_SPEED_USER_KBPS_VAL /* per menuconfig */
#endif



/* brief: rudi
 * over menuconfig you can set the cfg
 * defines are used in the head of code then
 * if you change to user cfg
 * you can change here too by your self
 * how you need this.
*/
CAN_device_t CAN_cfg = {
	.speed		= CONFIG_SELECTED_CAN_SPEED,	// CAN Node baudrade
	.tx_pin_id 	= CONFIG_ESP_CAN_TXD_PIN_NUM,	// CAN TX pin example menuconfif GPIO_NUM_5
	.rx_pin_id 	= CONFIG_ESP_CAN_RXD_PIN_NUM,	// CAN RX pin example menuconfig GPIO_NUM_4
	.rx_queue	= NULL,							// FreeRTOS queue for RX frames
};



esp_err_t event_handler(void *ctx, system_event_t *event)
{
    return ESP_OK;
}


void task_CAN( void *pvParameters ){
    (void)pvParameters;

    //frame buffer
    CAN_frame_t __RX_frame;

    //create CAN RX Queue
    CAN_cfg.rx_queue = xQueueCreate(10,sizeof(CAN_frame_t));

    //start CAN Module
    CAN_init();

    while (1){
        //receive next CAN frame from queue
        if(xQueueReceive(CAN_cfg.rx_queue,&__RX_frame, 3*portTICK_PERIOD_MS)==pdTRUE){

        	//do stuff!

			/* brief: rudi
			* new we switch to NODE Identifier here
			* only if we are interest to this comming node
			* we print / use the node date where commes in from
			*
			*/
			// if ( __RX_frame.MsgID == YOUR_CHOICE) {

			// printf("New Frame form 0x%08x, DLC %d, dataL: 0x%08x, dataH: 0x%08x \r\n",__RX_frame.MsgID,  __RX_frame.DLC, __RX_frame.data.u32[0],__RX_frame.data.u32[1]);
			printf("Frame from : 0x%08x, DLC %d \n", __RX_frame.MsgID, __RX_frame.DLC);
			printf("D0: 0x%02x, ", __RX_frame.data.u8[0]);
			printf("D1: 0x%02x, ", __RX_frame.data.u8[1]);
			printf("D2: 0x%02x, ", __RX_frame.data.u8[2]);
			printf("D3: 0x%02x, ", __RX_frame.data.u8[3]);
			printf("D4: 0x%02x, ", __RX_frame.data.u8[4]);
			printf("D5: 0x%02x, ", __RX_frame.data.u8[5]);
			printf("D6: 0x%02x, ", __RX_frame.data.u8[6]);
			printf("D7: 0x%02x\n", __RX_frame.data.u8[7]);
			printf("==============================================================================\n");
        	//loop back frame
        	CAN_write_frame(&__RX_frame);
			// } /* comment out if you use YOUR_CHOICE */

        }
    }
}

void task_CAN_TX(void* pvParameters) {

   CAN_frame_t __TX_frame;
   uint32_t counter = 0;

      __TX_frame.MsgID = CONFIG_ESP_CAN_NODE_ITSELF;
      __TX_frame.DLC   =  8;
      __TX_frame.data.u8[0] = 'E';
      __TX_frame.data.u8[1] = 'S';
      __TX_frame.data.u8[2] = 'P';
      __TX_frame.data.u8[3] = '-';
      __TX_frame.data.u8[4] = 'C';
      __TX_frame.data.u8[5] = 'A';
      __TX_frame.data.u8[6] = 'N';
      __TX_frame.data.u8[7] = counter;

while(1) {
      __TX_frame.data.u8[7] = counter;
      CAN_write_frame(&__TX_frame);
      vTaskDelay( 1000 / portTICK_PERIOD_MS);  // to see ( printf on receiver side ) what happend..
      counter++;
      if (counter >= 256) counter = 0;
  }
}



void app_main(void)
{
    nvs_flash_init();
    tcpip_adapter_init();
 /*
  *  Station Mode:
  */
    /*
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    wifi_config_t sta_config = {
        .sta = {
            .ssid = "access_point_name",
            .password = "password",
            .bssid_set = false
        }
    };
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );
*/

    /*
     *  Soft AP Mode
     */

	ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); // esp32_wifi_eventHandler
	wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
	ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
	ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
	ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
	wifi_config_t apConfig = {
	   .ap = {
	      .ssid="OpenCAN-home",
	      .ssid_len=0,
	      .password="not4upublic",
	      .channel=0,
	      .authmode=WIFI_AUTH_WPA2_PSK,               
	      .ssid_hidden=0,
	      .max_connection=4,
	      .beacon_interval=100
	   }
	};
	ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &apConfig) );
	ESP_ERROR_CHECK( esp_wifi_start() );


    
	/*brief: rudi
	* if you have "activate ESPCan"
	* then the code here runs..
	*
	*/
	#ifdef CONFIG_ESPCAN
	printf("ESPCan configured by this Data:\n");
	printf("Node           : 0x%03x\n", CONFIG_ESP_CAN_NODE_ITSELF);
	printf("CAN RXD PIN NUM: %d\n", CONFIG_ESP_CAN_RXD_PIN_NUM);
	printf("CAN TXD PIN NUM: %d\n", CONFIG_ESP_CAN_TXD_PIN_NUM);
	printf("CAN SPEED      : %d KBit/s\n", CONFIG_SELECTED_CAN_SPEED);

	#ifdef CONFIG_CAN_SPEED_USER_KBPS
	printf("kBit/s setting was done by User\n");
	#endif

	//Create CAN receive task
    xTaskCreate(&task_CAN, "CAN", 2048, NULL, 5, NULL);
		#ifdef CONFIG_CAN_TEST_SENDING_ENABLED
		vTaskDelay( 1000 / portTICK_PERIOD_MS);
		xTaskCreate(&task_CAN_TX, "task_CAN_TX", 2048, NULL, 5, NULL);
		#endif
	#endif

	/*brief: rudi
	* you can use the menuconfig ESPCan configs
	* like you need..
	* cause we have stdder if ESPCan is not enabled in this demo
	* this will never be called cause compilation will break
	* see #error message on top of the code
	*/
	#ifndef CONFIG_ESPCAN
	printf("Hello World without ESPCan ;-)\n");
	#endif

}




hope now is clear and helps,
if you use demo.zip - there is no need for the driver pack
and if you use driver pack with menuconfig - you do not need the drv folder from demo code and must clear main component.mk
and use only

Code: Select all

#include "CAN.h"
#include "CAN_config.h" 
btw
the demos code for a unit and a controll unit comes here in a few days
then there are websocket demos too, to monitoring CAN messages on webbrowser and
send CAN messages by link :) ( just in time project sceleton )

and sure - there comes animations too - but this comes easter....with an esp32 eclipse neon3 project --

best wishes
rudi ;-)
Last edited by rudi ;-) on Fri Mar 31, 2017 7:40 pm, edited 2 times in total.
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: About the CAN controller.

Postby jcsbanks » Wed Mar 29, 2017 11:38 am

Wow rudi, that is awesome, thanks very much! This is an amazing chip and forum, great support, you deserve to sell billions of ESP32.

I have got the ESP32 and a CAN bus tranceiver hooked up to a Kvaser Leaf Light, with termination resistance.

I can send a frame from Kvaser and the ESP32 receives it, but the Kvaser shows "error passive" and keeps resending the frame. Unless I add another CAN bus module like an engine ECU that acknowledges packets to the bus. I understand that all modules on a CAN bus normally acknowledge, but only one has to to keep the transmitter happy.

I added:

Code: Select all

	//disable listen only mode
	MODULE_CAN->MOD.B.LOM = 0;
but this is supposed to be the default value anyway, so changing it has not helped.

but it made no difference.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: About the CAN controller.

Postby jcsbanks » Wed Mar 29, 2017 4:00 pm

Bit more info after playing all afternoon.

The Tx pin is connected to the tranceiver from pin on ESP32 Devkit C to pin on the tranceiver chip, but the ESP32 cannot transmit. Pulling either Tx or Rx connection from ESP32 to tranceiver stops reception. The ECU only sends a single packet (but repeatedly) when powered up to the ESP32, until the Kvaser joins the CAN bus, then the ECU transmits its usual variety of IDs, so it looks like it is also diagnosing CAN off. I have swapped the Tx and Rx pins on ESP32 both physically and also in the software and I can still receive, so it doesn't seem like a faulty GPIO. It could be a faulty tranceiver I guess. Or some setting I'm missing or have messed up.

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: About the CAN controller.

Postby rudi ;-) » Wed Mar 29, 2017 11:45 pm

@jcsbanks

can you test the thing with alternative transceiver MCP2551 or TJA1051
.. i read you connect to the ESP32 Kvaser ..
- Kvaser Leaf Light HS v2
- Kvaser Leaf Light HS GI
- Kvaser Leaf Light HS v2 CB
- Kvaser Leaf Light HS v2 OBDII
conectors.png
conectors.png (73.51 KiB) Viewed 17985 times

i think you use: Kvaser Leaf Light v2 HS. Item No. 00685-0
can you point me to your used hw type in detail, please.

ok, you say,
if Kvaser send - then ESP32 is receive well
so the Tx from Kvaser goes ?...
- to an CAN Transceiver?
- to the Rx GPIO from ESP32?

importants are:
which high pegel does Kvaser use for sending / receive
cause ESP32 is 3.3V perhabs the Tx of ESP32 is not enough to the Kvaser?

usually goes here in CAN Transceiver ( MCP2551) <-> MCU ( ESP32 )
Rx to Rx
and Tx to Tx,
( not crossed like in USB TTL adapter.)
and cause ESP32 3.3V the pins must be level shifted if more or lees as 3.3v

i use the MCP2551 and connect it to esp32 GPIO4(rx) and GPIO5(tx)
the line on MCP2551 CAN_H and CAN_L is terminated with 120 Ohm and goes 100 m on a bus cable
the GND is connected to the GND/mass of the bus cable if i use a second Laptop for connect DevKitC on USB

on the other side there is the same ( DevKitC V2 and MCP2551 )
and the lines CAN_H and CAN_L are terminated with 120 Ohm
the Rx and Tx from MCP2551 goes to the ESP32 GPIO4(rx) and GPIO5(tx)

cause MCP2551 need 5 V ( so there comes a 4.78 V Pegel on Rx! )
i switched in the RX line a resistor ( 10 kOhm ) in the line
MCP2551 Rx---------Resistor 10kOhm--------ESPGpio4
so the rx signal has max 3.65V on gpio4 if high
btw:
do not do the same! can destroy your ESP32!
i have tested without this resistor too, and ESP32 works with this 4.78 V too,
but for the protocoll here :) - do not use this 4.78 V on ESP32 - this can destroy your ESP32
i have more ESP32 here for testing these things ;-) ( it works shortime with 5.23V too ) but this is unofficial! )

btw have you try to comment the line in the receive func
before

Code: Select all

// loop back frame
CAN_write_frame(&__RX_frame);
after

Code: Select all

// loop back frame
// CAN_write_frame(&__RX_frame);
let me know which Kvase you use and is there a CAN Transceiver on ESP32 or goes the RX TX line to the Kvase? ( Can_H, CAN_L )
cause like you can see,
Kvases have CAN_H and CAN_L
and you can't connect them to GPIO of ESP32 for "rx" and "tx" directly
you need a CAN Transceiver between Kvase and ESP32.

but i read
got the ESP32 and a CAN bus tranceiver hooked up to a Kvaser Leaf Light, with termination resistance.
`so i think you use an CAN bus transceiver between, can you point me to the Type of this please.

thank you

best wishes
rudi ;-)


ps:
we have here the best guys from all over the world ( ivan, jeroen, angus and the esp guys )
and special guys like here CAN from Thomas and Eric..
they teach us here every days more tricks, gimmicks and technic..
..so we can only reflect the input what they us teach :D
and here is a friendly forum too, so, you can allways calculate with an answere
we love all here the things here from espressif - this is more as friendship - this goes in family way :)
we argue sometimes loudly - but we also love each other afterwards but this is an other theme ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: About the CAN controller.

Postby jcsbanks » Thu Mar 30, 2017 10:43 am

Thanks rudi.

Yes I am using Kvaser Leaf Light v2 HS with OBD plug.
SN65HVD230 CAN bus tranceiver (3.3V).

Kvaser Leaf CAN H to SN65HVD230 CAN H.
Kvaser Leaf CAN L to to SN65HVD230 CAN L.
Kvaser Leaf GND pin 5 (signal ground) to to SN65HVD230 GND. I will try Kvaser Leaf GND pin 4 (chassis ground) and will also try without a ground connection

SN65HVD230 GND to ESP32 DEVKITC GND.
SN65HVD230 RS to ESP32 DEVKITC GND (also tried 120R and 10K to GND).
SN65HVD230 VCC to ESP32 DEVKITC 3.3V.
SN65HVD230 Vref not connected.
SN65HVD230 R to ESP32 DEVKITC pin "IO4".
SN65HVD230 D to ESP32 DEVKITC pin "IO5". I also tried a 10K pull up to 3.3V on IO5 - no difference.
SN65HVD230 CAN H 120R to CAN L. There is also 120R termination at the other end of the CAN bus. It is only 30cm long. I read 56 ohms between CAN H and CAN L. I will try 60R between CAN H and GND and 60R between CAN L and GND.

ESP32 DEVKITC powered from USB to microUSB cable connected to either laptop or 1.8A 5V supply (no difference). 3.3V rail is steady under load. 5V pin on DEVKITC reads 4.65V with any power source.

Code used: Thomas demo. I have also tried commenting out the loopback as you show - this was the only way to get lots of packets to display on the ESP32 terminal. If the loopback is present, only up to four packets are shown on the ESP32 terminal suggesting that the SJA1000 is falling into an error because of failure to transmit too? Tried 125kbps. Tried swapping IO4 and IO5 in software and hardware and same result.

I will also try to see what voltage I get between CAN H and CAN L with ESP32 DEVKITC IO5 set high and low.

This could all be a faulty tranceiver. I need to get more alternatives to test and get an oscilloscope.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: About the CAN controller.

Postby jcsbanks » Thu Mar 30, 2017 11:14 am

Connecting the D pin of the tranceiver to 3.3V, I read -1.1mV between CAN H and CAN L with the bus disconnected but with 120R termination.

Connecting the D pin of the tranceiver to 0V I read 0mV between CAN H and CAN L. I should be getting a positive voltage between CAN H and CAN L in this situation. So it must be a faulty tranceiver. I will report back when I try something else.

Thanks for the support! Hope the ideas and fault finding notes are useful to others, I will contribute further when I can.

Who is online

Users browsing this forum: No registered users and 34 guests