Emandhal / MCP251XFD

MCP2517FD, MCP2518FD and MCP251863 driver
MIT License
28 stars 6 forks source link

MCP251XFD driver library guide : minor enumerator misspelling #6

Closed BombaMat closed 2 years ago

BombaMat commented 2 years ago

Hello, I found a small mistake in the library guide.

For enum eMCP251XFD_CANCtrlFlags (page 48) :

It is written MCP251XFD_CAN_PROTOCOL_EXEPT_ENTER_INTEGRA instead of MCP251XFD_CAN_PROTOCOL_EXCEPT_ENTER_INTEGRA and MCP251XFD_CAN_PROTOCOL_EXEPT_AS_FORM_ERROR instead of MCP251XFD_CAN_PROTOCOL_EXCEPT_AS_FORM_ERROR

Doesn't cause trouble, just to be sure that you are aware of this spelling error.

Emandhal commented 2 years ago

Hi, Thank you for this.

Do you think the documentation is understandable or that there are parts that need more clarification?

Regards

BombaMat commented 2 years ago

The documentation is good overall.

From what I have seem, I would like more explanation on the function MCP251XFD_ConfigureFIFOList, is it OK to use it without TEF register ?

Second suggestion, having a complet summary of all the functions would be great. Kinda like they have done for the STM32 library. And also PDF summary to navigate faster through sections.

And last little thing, inline attribute doesn't seems to work in STM32 IDE, I made them regular function and it work this way. Will it really slow down the driver ?

UPDATE : MCP251XFD_ClearInterruptEvents function definition (page 96) have same description as MCP251XFD_GetCurrentInterruptEvent function

Emandhal commented 2 years ago

From what I have seem, I would like more explanation on the function MCP251XFD_ConfigureFIFOList, is it OK to use it without TEF register ?

Yes, if you don't set the TEF, it will be disabled by the function It is the same behavior for the TXQ I will update the documentation for this

Second suggestion, having a complet summary of all the functions would be great. Kinda like they have done for the STM32 library.

Can you be more specific, please?

And also PDF summary to navigate faster through sections.

I see how to do that, good idea

And last little thing, inline attribute doesn't seems to work in STM32 IDE, I made them regular function and it work this way. Will it really slow down the driver ?

Strange, maybe it is a C89 compiler? However it will not slow down the driver very much

UPDATE : MCP251XFD_ClearInterruptEvents function definition (page 96) have same description as MCP251XFD_GetCurrentInterruptEvent function

I will update this

BombaMat commented 2 years ago

Can you be more specific, please?

A list of all available functions with only there name, to be able to get a quick overview. With a link to their description for easy browsing.

Strange, maybe it is a C89 compiler? However it will not slow down the driver very much

It uses GNU11.

Concerning the speed of the driver, is it normal that the driver take almost 30 secondes to make init process (from init function to start function) ? I don't have safe functions that slow down the driver enabled.

Emandhal commented 2 years ago

Concerning the speed of the driver, is it normal that the driver take almost 30 secondes to make init process (from init function to start function) ? I don't have safe functions that slow down the driver enabled.

SPI clock speed? Do you have a Logic analyser to see what happen when the driver communicates?

BombaMat commented 2 years ago

SPI clock speed? Do you have a Logic analyser to see what happen when the driver communicates?

I'm using a 12 MHz clock for SPI. I don't have this kind of device, if problem continue I could try to get one.

Emandhal commented 2 years ago

I have to record an initialization based on the test of this repository. But as far as a remember, it takes less than 500ms for 2 MCP251XFD.

BombaMat commented 2 years ago

I have to record an initialization based on the test of this repository. But as far as a remember, it takes less than 500ms for 2 MCP251XFD.

This massive slowdown was caused by the STM32 Debug Tool, it is not a problem from the driver.

Now I am able to send and receive CAN messages with your library, but only with BRS disabled. Despite having the ControlFlag MCP251XFD_CANFD_BITRATE_SWITCHING_ENABLE and starting the device with MCP251XFD_StartCANFD. Maybe I missed something on how to do it ?

Emandhal commented 2 years ago

Can you show me your struct MCP251XFD and your struct MCP251XFD_Config please?

Emandhal commented 2 years ago

Do you set the MCP251XFD_CANFD_FRAME and MCP251XFD_SWITCH_BITRATE flags in the messageToSend->ControlFlags parameter of the MCP251XFD_TransmitMessageToFIFO function?

BombaMat commented 2 years ago

Can you show me your struct MCP251XFD and your struct MCP251XFD_Config please?

Here they are :

MCP251XFD MCP251XFD_Ext1 =
{
    //--- Optional user pointer ---//
    .UserDriverData = NULL,

    //--- Driver configuration ---//
    .DriverConfig = MCP251XFD_DRIVER_NORMAL_USE | MCP251XFD_DRIVER_ENABLE_ECC,

    //--- IO configuration ---//
    .GPIOsOutState = MCP251XFD_GPIO0_LOW | MCP251XFD_GPIO1_LOW,

    //--- SPI Communication parameters ---//
    .SPI_ChipSelect = CS_mkBUS1,                        // Using the mikroBUS 1 port
    .InterfaceDevice = &hspi2,                          // Connected to SPI 2
    .SPIClockSpeed = 12000000,                          // SPI at 12MHz speed

    //--- Interface driver call functions ---//
    .fnSPI_Init = MCP251XFD_InterfaceInit_STM32,        // Not used, init made by STM32
    .fnSPI_Transfer = MCP251XFD_InterfaceTransfer_STM32,
    .fnGetCurrentms = GetCurrentms_STM32,
    .fnComputeCRC16 = ComputeCRC16_STM32,
};
MCP251XFD_Config MCP2517FD_Ext1_Config =
{
     //--- Controller clocks ---//
     .XtalFreq = 0,                                     // CLKIN is not a crystal
     .OscFreq = 40000000,                               // CLKIN is a 40MHz oscillator
     .SysclkConfig = MCP251XFD_SYSCLK_IS_CLKIN,         // SYSCLK is CLKIN (no PLL, SCLK divide by 1)
     .ClkoPinConfig = MCP251XFD_CLKO_SOF,               // CLKO pin output Start Of Frame
     .SYSCLK_Result = &SYSCLK_Ext1,

     //--- CAN configuration ---//
     .NominalBitrate = 500000,                          // Nominal Bitrate to 500 kbps
     .DataBitrate = 2000000,                            // Data Bitrate to 2Mbps
     .BitTimeStats = &MCP2517FD_Ext1_BTStats,
     .Bandwidth = MCP251XFD_NO_DELAY,
     .ControlFlags = MCP251XFD_CAN_RESTRICTED_MODE_ON_ERROR         |
                     MCP251XFD_CAN_ESI_REFLECTS_ERROR_STATUS        |
                     MCP251XFD_CAN_RESTRICTED_RETRANS_ATTEMPTS      |
                     MCP251XFD_CANFD_BITRATE_SWITCHING_ENABLE       |
                     MCP251XFD_CAN_PROTOCOL_EXCEPT_ENTER_INTEGRA    |
                     MCP251XFD_CANFD_USE_ISO_CRC                    |
                     MCP251XFD_CANFD_DONT_USE_RRS_BIT_AS_SID11      ,

     //--- GPIOs and Interrupts pins ---//
     .GPIO0PinMode = MCP251XFD_PIN_AS_XSTBY,            // PIN is NC on STM32F4 Discovery, interrupt NOT AVAILABLE
     .GPIO1PinMode = MCP251XFD_PIN_AS_INT1_RX,
     .INTsOutMode = MCP251XFD_PINS_PUSHPULL_OUT,
     .TXCANOutMode = MCP251XFD_PINS_PUSHPULL_OUT,

     //--- Interrupts ---//
     .SysInterruptFlags = MCP251XFD_INT_ENABLE_ALL_EVENTS,
 };

Do you set the MCP251XFD_CANFD_FRAME and MCP251XFD_SWITCH_BITRATE flags in the messageToSend->ControlFlags parameter of the MCP251XFD_TransmitMessageToFIFO function?

For now I just send back the message I received. I am not able to receive them anyway.

Emandhal commented 2 years ago

I see no issue on both struct MCP251XFD and struct MCP251XFD_Config. I think I don't understand your problem. You can send and receive but with no BRS but after you said you are not able to receive them. I'm lost this time...

BombaMat commented 2 years ago

I see no issue on both struct MCP251XFD and struct MCP251XFD_Config. I think I don't understand your problem. You can send and receive but with no BRS but after you said you are not able to receive them. I'm lost this time...

I am able to receive and send back messages without BRS.

When I send messages with BRS to the MCP the receiver goes to Error Passive State and I get DiagStatus of 0x12.

Emandhal commented 2 years ago

This problem is not related to the driver. This is a CAN bus connection problem. Check terminaison resistors and the wiring of the bus. I can't do more at this stage. The driver seems to work as expected.

BombaMat commented 2 years ago

This problem is not related to the driver. This is a CAN bus connection problem. Check terminaison resistors and the wiring of the bus. I can't do more at this stage. The driver seems to work as expected.

I found my problem. Different sample rate on sender and receiver. From what I understand your library is targeting a sample rate of 80%, is this customizable ?

Emandhal commented 2 years ago

Yes, between the Init_MCP251XFD() function and the MCP251XFD_StartCANFD() function, fill a MCP251XFD_BitTimeConfig structure with your custom data and use the MCP251XFD_SetBitTimeConfiguration() function. Use the MCP251XFD_CalculateBitrateStatistics() function to know the exact result. I will add a paragraph for this case