I 've posted my CAN board on Tindie for anyone interested.
https://www.tindie.com/products/fusion/dual-can-bus-adapter-for-teensy-40-41/
https://www.tindie.com/products/fusion/dual-can-bus-adapter-for-teensy-40-41/
#include <FlexCAN_T4.h>
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
CAN_message_t msg;
uint8_t Temperature = 0;
uint8_t temp = 0;
void setup()
{
can1.begin();
can1.setBaudRate(125000);
}
void loop()
{
if (Temperature > 50 && temp == 0)
{
msg.mb = 1;
msg.id = 0x108180fe;
msg.len = 8;
msg.buf[0] = 0x01;
msg.buf[1] = 0x01;
msg.buf[2] = 0x00;
msg.buf[3] = 0x00;
msg.buf[4] = 0x00;
msg.buf[5] = 0x00;
msg.buf[6] = 0xa6; // Voltage 41.5
msg.buf[7] = 0x00;
can1.write(msg);
temp = 1;
} else if (Temperature < 45 && temp == 1)
{
msg.mb = 1;
msg.id = 0x108180fe;
msg.len = 8;
msg.buf[0] = 0x01;
msg.buf[1] = 0x01;
msg.buf[2] = 0x00;
msg.buf[3] = 0x00;
msg.buf[4] = 0x00;
msg.buf[5] = 0x00;
msg.buf[6] = 0xd6; // Voltage 53.5
msg.buf[7] = 0x00;
can1.write(msg);
temp = 0;
}
}
msg.flags.extended = 1;
I am very grateful to you for your answer!it looks like you are flooding the bus with writes, are you sure the device can process the data that fast? usually on cars we need to space the transmissions to a device at like 10ms, but your loop is constantly flooding the bus so.....
that is an extended ID, you should be using:
Code:msg.flags.extended = 1;
Maybe its just the extended flag, I relooked your code and see it's doing only a single transmission on a heat change, but because you are not using the flag, the CANID is truncated to 11bit instead of being 29bit..
msg.flags.extended = 1;
can1.setClock(CLK_60MHz);
unfortunately there are no changes, the delay remains the same 60 seconds (((ahh okay sorry Teensy 3.x doesn't use setClock, 4.x only.
you need to put that msg.flags.extended with your message you wanna send. put it under your msg.id = 0x108180fe;
unfortunately it gives nothingIs your CAN line properly terminated? what happens if you put can1.events() in the loop()?
#include <IFCT.h>
CAN_message_t msg;
void setup() {
Can0.setBaudRate(125000);
Can0.enableFIFO();
msg.ext = 1;
msg.id = 0x108180fe;
msg.len = 8;
msg.buf[0] = 0x01;
msg.buf[1] = 0x01;
msg.buf[2] = 0x00;
msg.buf[3] = 0x00;
msg.buf[4] = 0x00;
msg.buf[5] = 0x00;
msg.buf[6] = 0xd6; //Voltage
msg.buf[7] = 0x00;
Can0.write(msg);
}
void loop() {
}
unfortunately I don't understand a lot, I have no experience with these devices,if you dont read them they will stay full. reception and transmission have different mailboxes and dont depend on each other. You should try printing mailboxStatus() every couple seconds then, if it shows all TX mailboxes full, it means you have physical connection issues (transceiver not enabled via gpio? CAN termination resistance?)
2.0-2.5 volts, these levels correspond to Teensy,MCP2551 is a 5V transceiver, you need to make sure the communication is done at 3.3V or you risk damaging the pin on teensy. Or look for a 3.3V transceiver
I've been fighting this for two weeks now, I broke my whole head,No thats the way it sends, something wrong in your setup. if IFCT and FlexCAN_T4 both don't work it'd definately not the code
tonton81, I am very grateful to you for participating in my problem!have you checked with a can bus analyzer to see if data is going out? or try another can-equipped bus just to see if you can read the bus (using FIFO example). If you can't read the bus don't expect transmissions to work, if you can read the bus, best to check if your frame layout is correct for the device your talking to
yes, this is the document I use,well you need the manual for it then, i tried googling and came up with this:
https://github.com/craigpeacock/Huawei_R4850G2_CAN/blob/main/Protocol.xlsx
the IDs dont match what your sending or receiving, but since your receiving something it means your sending the wrong/right data to the wrong canid thats why it's not responding