You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Timo.
thanks for your suggestions. I'm still here to bother you about it: be patient. I used the software simulator, now I would like to have a PGN generated via firmware and inserted into a minimal bus. The example takes the Actisense listener that I modified like this that follow.
Obviously the two devices cannot communicate. It seems to me that the SN65HVD230 have the termination resistor... Is it necessary to remove it also in the case of point-to-point communications like this?
Do you see some problem in this simple source code ?
// DOIT ESP32 DEVKIT V1
//per usare ESP32 websocket il 15/04/24 si deve
//cmodificare il file Websockets.cpp
// da C:\Users\mercanti\Documents\Arduino\libraries\WebSockets\src\WebSockets.cpp
//mettendo #include <esp32/sha.h> invece di hwcrypto
// qualcouno dice di mettere #include "sha/sha_parallel_engine.h"
#include <Arduino.h>
//#define N2k_CAN_INT_PIN 2
//#define USE_N2K_CAN 1
//#define N2k_SPI_CS_PIN 10
#define ESP32_CAN_TX_PIN GPIO_NUM_5
#define ESP32_CAN_RX_PIN GPIO_NUM_4
#define N2k_CAN_INT_PIN 0xff
#include <NMEA2000_CAN.h>
#include <N2kMsg.h>
#include <NMEA2000.h>
#include <N2kMessages.h>
#include <ActisenseReader.h>
#include <Seasmart.h>
tActisenseReader ActisenseReader;
// Define READ_STREAM to port, where you write data from PC e.g. with NMEA Simulator.
#define READ_STREAM Serial
// Define ForwardStream to port, what you listen on PC side. On Arduino Due you can use e.g. SerialUSB
#define FORWARD_STREAM Serial
Stream *ReadStream=&READ_STREAM;
Stream *ForwardStream=&FORWARD_STREAM;
const unsigned long TransmitMessages[] PROGMEM = {130310L, // Outside Environmental parameters
};
// Send time offsets
#define TempSendOffset 0
#define SlowDataUpdatePeriod 1000 // Time between CAN Messages sent
bool IsTimeToUpdate(unsigned long NextUpdate) {
return (NextUpdate < millis());
}
unsigned long InitNextUpdate(unsigned long Period, unsigned long Offset = 0) {
return millis() + Period + Offset;
}
void SetNextUpdate(unsigned long & NextUpdate, unsigned long Period) {
while ( NextUpdate < millis() ) NextUpdate += Period;
}
void setup() {
// Define buffers big enough
NMEA2000.SetN2kCANMsgBufSize(8);
NMEA2000.SetN2kCANSendFrameBufSize(250);
NMEA2000.SetN2kCANReceiveFrameBufSize(250);
if (ReadStream!=ForwardStream) READ_STREAM.begin(115200);
FORWARD_STREAM.begin(115200);
NMEA2000.SetForwardStream(ForwardStream);
NMEA2000.SetMode(tNMEA2000::N2km_ListenAndSend);
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show bus data in clear text
NMEA2000.ExtendTransmitMessages(TransmitMessages);
if (ReadStream==ForwardStream) NMEA2000.SetForwardOwnMessages(false); // If streams are same, do not echo own messages.
NMEA2000.EnableForward(true);
NMEA2000.Open();
Serial.println("Hi, SIMULATOR on standard TX RX pin! --> ");
ActisenseReader.SetReadStream(ReadStream);
ActisenseReader.SetDefaultSource(75);
ActisenseReader.SetMsgHandler(HandleStreamN2kMsg);
}
void SendN2kTempPressure(void) {
static unsigned long SlowDataUpdated = InitNextUpdate(SlowDataUpdatePeriod, TempSendOffset);
tN2kMsg N2kMsg;
double Temperature = 0;
double BarometricPressure = 0;
if ( IsTimeToUpdate(SlowDataUpdated) ) {
SetNextUpdate(SlowDataUpdated, SlowDataUpdatePeriod);
Temperature = 31.5;
BarometricPressure = 1036;
Serial.printf("Temperature: %3.1f °C - Barometric Pressure: %6.0f Pa\n", Temperature, BarometricPressure);
SetN2kPGN130310(N2kMsg, 0, N2kDoubleNA, Temperature, BarometricPressure);
NMEA2000.SendMsg(N2kMsg);
}
}
#define MAX_NMEA2000_MESSAGE_SEASMART_SIZE 500
void HandleStreamN2kMsg(const tN2kMsg &N2kMsg) {
N2kMsg.Print(&Serial);
NMEA2000.SendMsg(N2kMsg,-1);
char buf[MAX_NMEA2000_MESSAGE_SEASMART_SIZE];
if ( N2kToSeasmart(N2kMsg,millis(),buf,MAX_NMEA2000_MESSAGE_SEASMART_SIZE)==0 ) return;
String mystring(buf);
Serial.println(mystring);
}
void loop() {
SendN2kTempPressure();
NMEA2000.ParseMessages();
ActisenseReader.ParseMessages();
}
I'm using "SN65HVD230 " and I've read what you wrote about it.
The text was updated successfully, but these errors were encountered:
SN65HVD230 is type of transceiver and it does not have termination resistor. It is another thing if you point to some module board using SN65HVD230.
You need always at least 1 max 2 termination restors. In test table with short bus length 1 is enough, but even then 2 can be used. Never connect more than 2 termination resistors.
You could use tN2kSyncScheduler class instead of IsTimeToUpdate. See. e.g., TemperatureMonitor.
Can not quickly find any problem with code. Check wireing and pin definitions.
Hi Timo.
thanks for your suggestions. I'm still here to bother you about it: be patient. I used the software simulator, now I would like to have a PGN generated via firmware and inserted into a minimal bus. The example takes the Actisense listener that I modified like this that follow.
Obviously the two devices cannot communicate. It seems to me that the SN65HVD230 have the termination resistor... Is it necessary to remove it also in the case of point-to-point communications like this?
Do you see some problem in this simple source code ?
I'm using "SN65HVD230 " and I've read what you wrote about it.
The text was updated successfully, but these errors were encountered: