Datasheet

Copyright © 2013 ARM Ltd. All rights reserved
CAN: Controller Area Network Lab using ST STM32 Cortex-M processors. www.keil.com
20
118 CAN_TxMsg.id = 33; /* initialize msg to send */
119 for (i = 0; i < 8; i++) CAN_TxMsg.data[i] = 0;
120 CAN_TxMsg.len = 1;
121 CAN_TxMsg.format = STANDARD_FORMAT;
122 CAN_TxMsg.type = DATA_FRAME;
Experimenting with the CAN software:
The default MCBSTM32E 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. Have the CAN project loaded as before.
Be in Edit (not Debug) mode.
We will modify these settings first: they are located in CanDemo.c near the lines as indicated:
1) How to change the ID from 11 to 29 bit and also change the ID value:
1. Modify line 118 from CAN_TxMsg.id = 33; to this: CAN_TxMsg.id = 0x1234567;
2. Change the value in line 121 from STANDARD_FORMAT to EXTENDED_FORMAT. You can also use a 1.
3. Click on Rebuild.
Enter Debug mode. Click on the RUN icon.
4. The CAN Communication window will display the new ID:
This was really easy to do !
2) Create more than one Data Byte in a message:
1. Stop the program STOP icon.
and exit Debug mode.
2. Modify line 120 from CAN_TxMsg.len = 1; to: CAN_TxMsg.len = 8;
3. Click on Rebuild.
Enter Debug mode.
4. Click on the RUN icon.
Select Analog Sweep ..3.3V.
5. Note the eight data bytes but only the first one has a value:
This was also really easy to do !
3) Fill in the Seven Data Bytes:
1) Stop the program STOP icon.
and exit Debug mode.
2) Just after line 133: CAN_TxMsg.data[0] = val_Tx; /* data[0] = ADC value */
ADD this line to fill in the data bytes: for (i = 1; i < 8; i++) CAN_TxMsg.data[i] = 0x77;
3) Click on Build.
Enter Debug mode.
4) Click on the RUN icon.
5) Select Analog Sweep ..3.3V
6) Now you can see 0x77 added to the seven data
bytes. You should have no trouble to insert your own data values with suitable software changes.
4) Acceptance Filter: If you look in the data members for CAN_RxMsg in the Watch 1 window, you will not see the data
changing. The Acceptance Filter (setup in Can.c) is turned on blocking everything except ID 0x21. However, the CAN
Communication window can see IDs other than 0x21. The LA will not display the variable val_Rx. On a real CAN board
(see the next page), Rx will not display any data. Page 28 describes how to turn the filters off.
6. After you make changes it is advisable to save them and all of your other settings (such as trace and breakpoints).
Select File/Save All. Closing µVision also saves all modified files and settings.
This is the end of the Simulator exercises. For the next exercises, you need a STM32 CAN board such as the STM32F4
Discovery.