I'm reviewing the Microchip CAN Analyzer for a Road Test. It'll be used in a CAN Bus that I'm designing. This blog shows that it is useful in a firmware design cycle. |
The Analyzer as a Development Helper
In a previous CAN blog I wrote about configuring a Hercules microcontroller's CAN module. My setup is using interrupts to react on traffic and capture only relevant data.
The trigger should only fire when a message with ID == 1 appears on the CAN bus. Any other ID should be ignored. The CAN module should not interrupt the ARM controller.
An ideal scenario for the CAN Analyzer. I can use it to send a payload and choose an idea. It allows to generate messages to be captured and also ones to be ignored.
Here's the service routine:
#pragma WEAK(canMessageNotification) void canMessageNotification(canBASE_t *node, uint32 messageBox) { /* enter user code between the USER CODE BEGIN and USER CODE END. */ /* USER CODE BEGIN (15) */ if((node==canREG1)&& (messageBox == canMESSAGE_BOX1)) // transmit box { tx_done=1; /* confirm transfer request */ } if((node==canREG1)&& (messageBox == canMESSAGE_BOX2)) // receive box { while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2)); canGetData(canREG1, canMESSAGE_BOX2, rx_ptr); /* copy to RAM */ rx_ptr +=8; } /* USER CODE END */ }
These lines of code are of interest here:
if((node==canREG1)&& (messageBox == canMESSAGE_BOX2)) // receive box { while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2)); canGetData(canREG1, canMESSAGE_BOX2, rx_ptr); /* copy to RAM */ rx_ptr +=8; }
canREG1 is there because we're working with CAN module 1 of the microcontroller (it has 2 of them).
canMESSAGE_BOX2 is the message box of that CAN module that we've configured as an inbound box, listening to ID 1 only.
Test Scenarios
I've tested the following cases:
- trigger should not fire if ID is different than 1 (because I haven't defined a trigger for any other ID in the controller configuration).
- trigger should fire if ID is 1.
- if triggered, the following condition should evaluate TRUE:
if((node==canREG1)&& (messageBox == canMESSAGE_BOX2)) // receive box
- the payload should be copied to the controller's memory by the service routine
- send multiple messages.
All of the cases passed. Here's the result of a breakpoint firing after the first arrival of a message with ID == 1.
In the CAN Analyzer GUI, I set the ID to 1, the size to 8 bytes, and no repeats.
You can see that the Hercules stopped at the service routine's breakpoint, and copied the payload to the RAM:
canGetData(canREG1, canMESSAGE_BOX2, rx_ptr); /* copy to RAM */
I'm showing the content of the first 8 bytes of that RAM buffer in the upper right of the capture. You can see that the values 1 -> 8 that I sent via the Microchip CAN analyzer are now in the RAM buffer.
In the past I have been testing these scenarios by programming another CAN enabled microcontroller.
The Analyzer makes this easier.
Top Comments