arduino-esp32
arduino-esp32 copied to clipboard
twai_transmit(&message, 0); returns error 259
Board
ESP32-S3-WROOM-1
Device Description
I connected the SN65HVD230DR transceiver
In the last test I found that the problem persists even without anything connected except the logic analyzer on pin 21
Hardware Configuration
GPIO20 and GPIO21 connect to RX and TX of SN65HVD230DR
Version
v2.0.11
IDE Name
Arduino IDE 2.2.1
Operating System
WIN 11
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
I uploaded the sketch to two different devices:
ESP32-S3-WROOM-1 M0N8R8: everything works correctly With the transciver connected to the twai_transmit(&message, 0); it returns 0 while with the transciver disconnected it returns 263
ESP32-S3-WROOM-1 MCN16R2: both with transciver and without the twai_transmit(&message, 0) function; it always returns 259 to me. if I load a simple click on pin 21 with the logic analyzer I see the signal correctly. if I run this sketch it doesn't give me any signal and it always responds with error 259
Before trying with another ESP to avoid it being a chip problem, are there any further tests I can do? is there much difference compared to what is due? Thank you
Sketch
#include <arduino.h>
#include "driver/twai.h"
#define RX_PIN 20
#define TX_PIN 21
//#define CAN_RS 2
#define CAN_REQST_ID 0x7DF
void setup() {
Serial.begin(115200);
//pinMode(CAN_RS, INPUT); // INPUT (high impedance) = slope control mode, OUTPUT = see next line
//digitalWrite(CAN_RS, LOW); // LOW = high speed mode, HIGH = low power mode (listen only)
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)TX_PIN, (gpio_num_t)RX_PIN, TWAI_MODE_NORMAL); // TWAI_MODE_NORMAL, TWAI_MODE_NO_ACK or TWAI_MODE_LISTEN_ONLY
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_500KBITS();
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
twai_driver_install(&g_config, &t_config, &f_config);
twai_start();
}
void loop() {
Serial.println(CANsend());
Serial.println("Message sent!");
delay(1000);
}
int CANsend (void) {
twai_message_t message;
message.identifier = CAN_REQST_ID;
message.extd = 0;
message.rtr = 0;
message.data_length_code = 8;
message.data[0] = 2;
message.data[1] = 1;
message.data[2] = 5;
message.data[3] = 12;
message.data[4] = 97;
message.data[5] = 0;
message.data[6] = 0;
message.data[7] = 0;
return twai_transmit(&message, 0);
}
Debug Message
verbose and without errors
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
I would assume you are getting an INVALID_ARG error from the driver init. Try different pins or a lower bit rate and see if you can get error 263 (TIMEOUT) instead of 259 (INVALID_STATE). Note that pin 20 is typically one of the USB pins. Are you sure your N32R8 is a WROOM-1, not WROOM-2?
- I tried moving the transciver soldered onto the board and connecting it to an ESP32-S3 DEVKit-C (ESP32-S3-WROOM-1 M0N8R8) and it works.
- I tried to delete ADUM1401 (which is the only device in the way) but it doesn't work.
- I tried with another ESP32-S3-WROOM-1 MCN16R2 and it doesn't work.
- I tried with a speed of 500kbits, 12.5kbits, 1mbits but it doesn't change either.
- In all cases I receive message 0 for a few seconds and then message 259.
- With the oscilloscope I checked the tx pin of the transciver and I receive as many pulses as the responses with code 0 and then a constantly high value while receiving the error 259.
- The chips used are WROOM-1.
- I still tried with a WROOM-2 M0N32R8V and it works (tested with the receiving part but I don't think it changes much)
The variability that remains is just the different part number of the chip, could it be the revision of the chip? one has the suffix M0 while the other MC.
Another variability is the loading configuration, below you will find a screen
Thank you
Try setting USB Mode to USB-Tiny, which should leave the usb pins unattached. Did you try on different pins?
Hi, I solved it by finding an RS track that didn't make a false contact under the soldermask