Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility <FlexCAN_T4.h> and <NativeEthernet.h> #72

Open
Cand0o0 opened this issue Feb 9, 2024 · 1 comment
Open

Compatibility <FlexCAN_T4.h> and <NativeEthernet.h> #72

Cand0o0 opened this issue Feb 9, 2024 · 1 comment

Comments

@Cand0o0
Copy link

Cand0o0 commented Feb 9, 2024

Hi all,

Thank's a lot for your work.
I'm currently on a Teensy 4.1 and I'm trying to use <FlexCAN_T4.h> and <NativeEthernet.h>.
I used the code of mjs513 and it's worked for me too.

I want to communicate with my teensy by Ethernet with IP protocol, using <NativeEthernet.h>.
When I use the librairy separatly, it's work, but when I use it together, nothing work.

Any ideas ?

My code below :

// -------------------------------------------------------------
// CANtest for Teensy 4.0 using CAN2 and CAN2 bus
#include <FlexCAN_T4.h>
#include <NativeEthernet.h> // librairie ethernet pour teensy

/IP****/
#define IP1 10
#define IP2 0
#define IP3 20
#define IP4 130
/********************************************/

#define debug(msg) Serial.print("["); Serial.print(FILE); Serial.print("::"); Serial.print(LINE); Serial.print("::"); Serial.print(msg); Serial.println("]");
void debug_pause(void)
{
Serial.print("Paused...");
while (!Serial.available());
while (Serial.available()) Serial.read();
Serial.println("Restarted.");
}

FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> Can2;

static CAN_message_t msg;
static uint8_t hex[17] = "0123456789abcdef";

// -------------------------------------------------------------
static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
{
uint8_t working;
while( dumpLen-- ) {
working = *bytePtr++;
Serial.write( hex[ working>>4 ] );
Serial.write( hex[ working&15 ] );
}
Serial.write('\r');
Serial.write('\n');
}

// -------------------------------------------------------------
void setup(void)
{
Serial.begin(115200);
int iSerialTimeout = 1000000;
delay(100);
while (!Serial && (iSerialTimeout-- != 0));
debug (F("start setup"));

Can1.begin();
Can2.begin();
Can1.setBaudRate(1000000); //[COLOR="#FF0000"]// I like to set the baud rates just to be on the safe side[/COLOR]
Can2.setBaudRate(1000000);

// t4 missing msg.ext = 0;
msg.id = 0x100;
msg.len = 8;
msg.flags.extended = 0;
msg.flags.remote = 0;
msg.flags.overrun = 0;
msg.flags.reserved = 0;
msg.buf[0] = 10;
msg.buf[1] = 20;
msg.buf[2] = 0;
msg.buf[3] = 100;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;
debug (F("setup complete"));
//debug_pause();

/********** TCP **********/
byte mac[] =
{
0xDE, 0xAC, 0xDE, 0xEF, 0xAE, 0xEC
};

IPAddress ip(IP1, IP2, IP3, IP4); // adresse ip de la teensy
IPAddress subnet(255, 255, 255, 0); // netmask de la teensy
IPAddress gateway(IP1, IP2, IP3, 1); // gateway de la teensy
IPAddress myDns(IP1, IP2, IP3, IP4); // adresse dns de la teensy
//Ethernet.macAddress(mac);
Ethernet.MACAddress(mac);
//Ethernet.begin(ip,netmask,gateway,myDns); // initialisation des donnee ethernet avec la librairie QNEthernet begin(ip,mask,gateway,dns)
Ethernet.begin(mac, ip, myDns, gateway, subnet); // avec NativeEthernet
}

// -------------------------------------------------------------
void loop(void)
{
msg.buf[0]++; //[COLOR="#FF0000"] //since you are in a loop i just incremented each time in stead of doing it 5 times[/COLOR]
Can1.write(msg); //[COLOR="#FF0000"] //you could do it your way as well[/COLOR]
Serial.println("T4.0cantest - Repeat: Read bus2, Write bus1");
CAN_message_t inMsg;
if (Can2.read(inMsg)!=0) //[COLOR="#FF0000"]// Changed this to if as as opposed to while - the way you had it just gets stuck since you haven't even sent a message yet[/COLOR]
{
Serial.print("W RD bus 2: "); hexDump(8, inMsg.buf);
}
delay(20);
}

@Cand0o
Copy link

Cand0o commented Mar 27, 2024

It's ok, you can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants