CAN Bus project help needed with Flex CAN_T4 and extended frames

Dsolberg8132

Active member
I need to write a function that will communicate with a Huawei R4850G2 power supply using its' CAN Bus interface. I am using a Teensy 4.1 and a printed circuit board from a 3rd party source that connects the Teensy 4.1 to a SN65HVD234 CAN Bus xcvr on CAN3. The CAN bus interface is just one small part of a much larger project monitoring and controlling a Ham solid state amplifier. This is the last function that I need to write. Most of my other functions were written for use on an Arduino Mega. These functions have been ported to the Teensy and I have written some new ones, which has give me experience with the Teensy 4.1.

The Huawei communicates at 125 kbps baud rate using extended frames.

To receive data frames with information about the power supply, such as voltage and current, you have to send a request to 0x108040FE, with the data value frames padded with zeros. The supply then responds with 0X1081407F with frames of data.

I have no previous experience with CAN bus communication so this has already been a long journey. I bought a 3rd party controller that communicates with the Huawei supply for monitoring and also for setting values. Using this controller and a USB CAN Analyzer I can monitor the interaction. I know what messages that I have to send and what responses I can expect back.

I found some sample sketches on this forum that I have been using to learn more about the CAN bus communication. Using the Flex CAN_T4 library I am able to send data frames that I can monitor on the USB CAN Bus Analyzer. I can not enter the request data frame as the msg.id. If I send smaller numeric data values the data frames are coming across as "standard" frames in the USB CAN Bus Analyzer.

What do I need to do to enable the use of "extended" frames?

Don
 
@Dsolberg8132: If you look in the FlexCAN_T4.h file, the definition of the CAN_message_t appears as follows:

Code:
typedef struct CAN_message_t {
  uint32_t id = 0;          // can identifier
  uint16_t timestamp = 0;   // FlexCAN time when message arrived
  uint8_t idhit = 0; // filter that id came from
  struct {
    bool extended = 0; // identifier is extended (29-bit)
    bool remote = 0;  // remote transmission request packet type
    bool overrun = 0; // message overrun
    bool reserved = 0;
  } flags;
  uint8_t len = 8;      // length of data
  uint8_t buf[8] = { 0 };       // data
  int8_t mb = 0;       // used to identify mailbox reception
  uint8_t bus = 0;      // used to identify where the message came from when events() is used.
  bool seq = 0;         // sequential frames
} CAN_message_t;

If you define your CAN message variable as CAN_message_t custom_CAN;, then you can try setting the custom_CAN.flags.extended field to "1" to indicate that the frame is an extended frame.

Hope that helps . . .

Mark J Culross
KD5RXT
 
I am sending and recieving data frames to and from the Hauwei power supply. In addition to the data frames that I want, it is also sending out 0x1001117FE which I don't need. This frames is being recieved continuously. Is there a way to filter this out?

Don K9AQ
 
I am sending and recieving data frames to and from the Hauwei power supply. In addition to the data frames that I want, it is also sending out 0x1001117FE which I don't need. This frames is being recieved continuously. Is there a way to filter this out?

Don K9AQ

Yes, most CAN interfaces (including the one in the Teensy) have the ability to create hardware filters to allow / block certain IDs so that the processor only gets notified about packets you care about.
A quick look found this thread on using them, there are probably some more examples around if you search for FlexCAN and filter. https://forum.pjrc.com/index.php?th...tting-filters-with-the-flexcan-library.55719/

Having said that the Teensy 4 had silly amounts of processing power and your CAN bus is running really slowly. In your situation I'd be tempted to handle it in software and simply ignore the packets with the wrong address. It'll be a tiny performance hit but is far simpler that worrying about setting up the filters.
 
According to <this> file (which provides the CAN protocol for the Huawei R4875G1), the 0x1001117E status is as follows:

This is an unsolicited message reporting the DC current, encoded in the last four bytes

Maybe the function of this status message is similar in your unit (R4850) ??

Mark J Culross
KD5RXT
 
I was able to confirm that the CAN protocol is the same for both models. I need a back up supply so I think I am going to buy an R4875G. My amplifier is a dual BLF188XR with water cooling . I don't need a 4KW power supply but it would give me a lot of head room when running at 1.5KW!

Don K9AQ
 
@Dsolberg8132: If you look in the FlexCAN_T4.h file, the definition of the CAN_message_t appears as follows:

Code:
typedef struct CAN_message_t {
  uint32_t id = 0;          // can identifier
  uint16_t timestamp = 0;   // FlexCAN time when message arrived
  uint8_t idhit = 0; // filter that id came from
  struct {
    bool extended = 0; // identifier is extended (29-bit)
    bool remote = 0;  // remote transmission request packet type
    bool overrun = 0; // message overrun
    bool reserved = 0;
  } flags;
  uint8_t len = 8;      // length of data
  uint8_t buf[8] = { 0 };       // data
  int8_t mb = 0;       // used to identify mailbox reception
  uint8_t bus = 0;      // used to identify where the message came from when events() is used.
  bool seq = 0;         // sequential frames
} CAN_message_t;

If you define your CAN message variable as CAN_message_t custom_CAN;, then you can try setting the custom_CAN.flags.extended field to "1" to indicate that the frame is an extended frame.

Hope that helps . . .

Mark J Culross
KD5RXT
I have a separate question, but it's on the same topic so I thought I just ask here.
I currently have 4 ID's that I'm filtering for using the mailboxes, and the can bus its attached to has a high update rate, so i want to be able to poll the mailboxes periodically and pass that on to nrf 24. I've been looking through the examples and library, and I dont really know what approach to take. Should i still be using the interrupts and callbacks, is there a different way of doing this? Does anyone know of any examples out there on something similar?
Thanks in advance :)
 
Back
Top