Hello,
I want to use freemaster to communicate with the mcu over CAN bus.
I have googled the tutorial but found nothing. Is there any demo which can explain the basic how-to? I want to know how to add the related code to my project in S32DS. I am using S32K144-EVB.
解決済! 解決策の投稿を見る。
Hi @Jimny,
There are 2 things that need minor adjustments, one is in your code and another one related to the SDK:
#if FMSTR_SHORT_INTR || FMSTR_LONG_INTR
INT_SYS_InstallHandler(CAN0_ORed_0_15_MB_IRQn, FMSTR_Isr, NULL);
INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
#endif
If you don't want to use interrupts, you can switch to polling mode:#define FMSTR_LONG_INTR 0 /* Complete message processing in interrupt */
#define FMSTR_SHORT_INTR 0 /* SCI FIFO-queuing done in interrupt */
#define FMSTR_POLL_DRIVEN 1 /* No interrupt needed, polling only */
/* Enter Freeze mode */
CAN0->MCR |= (CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);
CAN0->MCR &= ~CAN_MCR_MDIS_MASK;
while((CAN0->MCR & CAN_MCR_FRZACK_MASK ) == 0){}
/* Disable abort mechanism MCR[AEN] = 0 */
CAN0->MCR &= ~CAN_MCR_AEN_MASK;
/* Enable the FlexCAN module */
CAN0->MCR &= ~(CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);
I also attached my main.c that should work in both modes. Let me know if it helps fixing your issue.
Regards,
Iulian
Hi @Jimny,
Could you please provide some additional details about your case:
In the meantime you can check this post - it's a bit outdated, but can give a base understanding of FreeMASTER Driver. I will provide updated instructions to match the tools you are working with.
Kind regards,
Iulian
Hello, iulianstan
Thank you for your reply.
The driver is already enabled and I have issues configuring it.
I use S32DS for ARM 2.2 and S32K144_SDK 3.0.0.
Let me describe the issue in detail.
I have created a new project and configure the can_pal.
I have changed the configuration in freemaster_cfg.h to use the can bus.
In the main function, I initialized the clock and can peripherals. And the FMSTR_Init(), FMSTR_Poll() functions were also added.
Then I compiled the program and flashed it.
A freemaster project has been created to test the demo. I choose to connect the board over can bus.
Then I clicked the Plug-in Configuration.
I use GY8507 interface card from GLINKER. It seems the driver is ok. When I clicked the Test Connection, an error occured.
I think I should have missed some configuration in the code. Please see the project in the attachment.
By the way, I have tested the model in the MBDT named "CAN_With_FreeMASTER_over_CAN", it works.
Hi @Jimny,
There are 2 things that need minor adjustments, one is in your code and another one related to the SDK:
#if FMSTR_SHORT_INTR || FMSTR_LONG_INTR
INT_SYS_InstallHandler(CAN0_ORed_0_15_MB_IRQn, FMSTR_Isr, NULL);
INT_SYS_EnableIRQ(CAN0_ORed_0_15_MB_IRQn);
#endif
If you don't want to use interrupts, you can switch to polling mode:#define FMSTR_LONG_INTR 0 /* Complete message processing in interrupt */
#define FMSTR_SHORT_INTR 0 /* SCI FIFO-queuing done in interrupt */
#define FMSTR_POLL_DRIVEN 1 /* No interrupt needed, polling only */
/* Enter Freeze mode */
CAN0->MCR |= (CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);
CAN0->MCR &= ~CAN_MCR_MDIS_MASK;
while((CAN0->MCR & CAN_MCR_FRZACK_MASK ) == 0){}
/* Disable abort mechanism MCR[AEN] = 0 */
CAN0->MCR &= ~CAN_MCR_AEN_MASK;
/* Enable the FlexCAN module */
CAN0->MCR &= ~(CAN_MCR_FRZ_MASK | CAN_MCR_HALT_MASK);
I also attached my main.c that should work in both modes. Let me know if it helps fixing your issue.
Regards,
Iulian
Hi, @iulian_stan
Your solution works! Thank you very much.