sandeepmistry/arduino-CAN

Learning how to work with the CAN bus.

Opened this issue ยท 0 comments

Good day @sandeepmistry ๐Ÿ™‚

I take this module, I replaced CAN transceiver microcircuit with SN65HVD230

Now the board is powered by 3.3 volts.

371743157-365de5d0-316b-4fdb-95be-c90e3fd538c6

I connect it via the SPI bus to the STM32 microcontroller

stm32f411ceu6

I took this example:
https://github.com/sandeepmistry/arduino-CAN/blob/master/examples/CANSender/CANSender.ino

First, I set the desired CS pin

CAN.setPins(PA4); // CS = PA4

Then I set the quartz frequency, I have 8 MHz on my board

CAN.setClockFrequency(8e6); // default 16e6 - 16 MHz quarz

And ser 125000 baudRate

CAN.begin(125E3))

When the code is loaded into the MCU and transmission begins, such code

CAN.beginPacket(0x12);
CAN.write('h');
CAN.write('e');
CAN.write('l');
CAN.write('l');
CAN.write('o');
CAN.endPacket();
Overflows the frame, which transmits only 8 bytes of data.

The signal analyzer sees the frame, but it fails.
I interpreted this as the frame size being exceeded.

CAN_hello_error

Replacing the code with this

const char* message = "Hello, World!"; // Message with a length of 13 bytes
size_t messageLength = strlen(message); // Get the length of the message
size_t offset = 0;                       // Initialize offset to keep track of the current position

while (offset < messageLength) {         // Continue until all data is sent
    CAN.beginPacket(0x12);               // Begin a packet with identifier 0x12

    // Write up to 8 bytes of data
    for (int i = 0; i < 8 && (offset + i) < messageLength; ++i) {
        CAN.write(message[offset + i]);   // Write each byte from the message
    }

    CAN.endPacket();                      // End the packet
    offset += 8;                          // Increment offset by 8 to move to the next chunk of data
}

I get a line with the correct checksum and NAK at the end.

CAN_hello_NAK

Without the jumper, the data on the bus was always ERROR, perhaps because I only have one board so far, and there is no second one, and only the signal analyzer takes data.

When I installed the jumper J1, the data immediately appeared.

I have only just begun to understand the CAN bus and many things remain mysteries.