Datasheet

Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
28
102 CAN_TxMsg.id = 33; /* initialize msg to send */
103 for (i = 0; i < 8; i++) CAN_TxMsg.data[i] = 0;
104 CAN_TxMsg.len = 1;
105 CAN_TxMsg.format = STANDARD_FORMAT;
106 CAN_TxMsg.type = DATA_FRAME;
Experimenting with the CAN software:
The default CAN example produces a CAN frame with an ID of 0x21 and one data byte. We will make some modifications
to CanDemo.c to show how easy it is to modify it for your own uses.
1. Have the CAN project loaded as before. Close the Trace Records window. Exit Debug mode. Close the LA.
1) Turn OFF CAN Filters and configure Watch 1:
1. Go near lines 223 and 229 in CAN.c. Swap the two comment fields as indicated: //!!* To disable the CAN Filters:
2. In Watch 1 add these two structures if needed: CAN_TxMsg and CAN_RxMsg as shown below:
We will modify various CAN fields to see the effect: they are located in CanDemo.c near the lines as indicated:
2) How to change the ID from 11 to 29 bit and also change the ID value:
7. Modify line 102 in CanDemo.c from CAN_TxMsg[1].id = 33; to this: CAN_TxMsg[1].id = 0x12345678;
8. Change the value in line 105 from STANDARD_FORMAT to EXTENDED_FORMAT. You can also use a 1.
9. Click on Rebuild.
Program the Flash. Enter Debug mode.
10. Select CAN_RxMsg[0] in the Watch 1 window:
11. Click on the RUN icon.
The new ID is displayed as shown here:
Note that these values are updated in real-time as the program runs.
This was really easy to do !
3) Create more than one Data Byte in a message:
6. Stop the program STOP icon.
and exit Debug mode.
7. Modify line 104 in CanDemo.c from CAN_TxMsg[1].len = 1; to:
CAN_TxMsg[1].len = 8;
8. Click on Rebuild.
Program the Flash. Enter Debug mode.
9. Click on the RUN icon.
:
10. Note first data byte changes and the rest are 0x77:
This was also really easy to do !
4) Change the Seven Data Bytes:
7) Stop the program STOP icon.
and exit Debug mode.
8) Near line 117: for (i = 1; i < 8; i++) CAN_TxMsg[1].data[i] = 0x77;
9) Change 0x77 to 0x23. This will change the data bytes 1 through 7.
10) Click on Rebuild.
Program the Flash. Enter Debug mode.
11) Click on the RUN icon.
12) In CAN_Msg[0] you can see the data bytes 1 through 7 are now 0x23. You should have no trouble to put your
own data in with suitable source code.
This is the end of the exercises. I hope they have been informative.
The rest of this document offers some useful information about CAN and debugging in general.