espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.75k stars 7.43k forks source link

ESP32 wroom-32e #10327

Open taoloo897 opened 2 months ago

taoloo897 commented 2 months ago

Board

ESP32 wroom-32e

Device Description

can not make canbus work, i used a SN65HVD230 and twai library with esp32 board updated to 3.0.4 (not work on 2.0.11 too)

Hardware Configuration

i tried pin 4 and 5 and other 32 +34 it is a board with esp 32 wroom 32e with 1 channel relay

Version

v3.0.4

IDE Name

arduino ide

Operating System

windows 11

Flash frequency

80

PSRAM enabled

yes

Upload speed

921600

Description

, i tried to double the init speed , not work any suggestions please

twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)TX_PIN, (gpio_num_t)RX_PIN, TWAI_MODE_NORMAL);

twai_timing_config_t t_config = TWAI_TIMING_CONFIG_1MBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); twai_driver_install(&g_config, &t_config, &f_config); twai_start();

Sketch

#include "driver/twai.h"
#include "Arduino.h"
#define DEBUG
#define USB_SPEED     500000 // 115200 230400 250000 500000
//#define RX_PIN        44 //can rx
//#define TX_PIN        43 //can tx
#define RX_PIN        5 //can rx
#define TX_PIN        4 //can tx

#define PIN_RELEU     16

void setup() 
{
  #ifdef DEBUG
    Serial.begin(USB_SPEED);  
  #endif

  twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)TX_PIN, (gpio_num_t)RX_PIN, TWAI_MODE_NORMAL);  
  //twai_timing_config_t t_config  = TWAI_TIMING_CONFIG_500KBITS();
  twai_timing_config_t t_config  = TWAI_TIMING_CONFIG_1MBITS();
  twai_filter_config_t f_config  = TWAI_FILTER_CONFIG_ACCEPT_ALL();
  twai_driver_install(&g_config, &t_config, &f_config);
  twai_start();

  delay(500);

  pinMode(PIN_RELEU, OUTPUT);

}

void loop()
{
    citesc_CAN(); 
}

void citesc_CAN(void)
{
  twai_message_t message;

  if (twai_receive(&message, 1) == ESP_OK)
  { 
      //tft.drawString(String(message.identifier,HEX), 1, 80, 4);      
      Serial.println(message.identifier,HEX);
      delay(10);
      /*   for(int i=0;i<message.data_length_code;i++) 
          {

            Serial.print("  \t0x");
            if (message.data[i]<=0x0F) {
              Serial.print(0);
            }
            Serial.print(message.data[i], HEX);
          }
          Serial.println();*/

      switch (message.identifier)
      {
        case 0x448:
        {    
          if (message.data[0] == 0x72)
          {          
            digitalWrite(PIN_RELEU, HIGH);
          } 
          else 
          {
            digitalWrite(PIN_RELEU, LOW);
          }
          break;
        }
        default:
        {                            
          break;
        }
      }
  }

  else
  {      
    #ifdef DEBUG
      Serial.println("can error");
    #endif  
  }
}

Debug Message

"can error" from this is if (twai_receive(&message, 1) == ESP_OK)
because the answer is wrong

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

lbernstone commented 2 months ago

This is the expected behavior if no message is received. You need to capture the result of twai_receive and if it is ESP_ERR_TIMEOUT then it has simply timed out. You really ought to check the result of twai_driver_install to make sure that is ESP_OK as well.

taoloo897 commented 2 months ago

It has a big delay, I had a delay(10) in receive and if i comment it , i receive ok (with little delay between frames) I tried with (twai_receive(&message, 1) == ESP_OK) and with 0 (twai_receive(&message, 0) == ESP_OK) No difference.

BUTTTTT if i leave like upstairs in TWAI_MODE_NORMAL) , i don;t received any frame . I must put in MODE_LISTEN_ONLY. With other esp boards 32U and S3 , the same sketch works ok.