This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:hardware:avr-can:exercise_1 [2010/04/05 12:58] – created mikk.leini | en:hardware:avr-can:exercise_1 [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Exercises ====== | ||
| + | ====Exercise 1==== | ||
| + | |||
| + | For this exercise you will use the CAN board with the USB_CAN.hex program | ||
| + | (board 1) and a second CAN board (board 2). Board 2 is similar to board 1, | ||
| + | except that it is not programmed yet. You will also use the USB-CAN-Terminal | ||
| + | program for the visualisation of CAN communication. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Figure 1.21: Setup and alternative | ||
| + | |||
| + | The left picture shows the set-up you will use for this assignment. CAN-messages | ||
| + | will be visualised by the CAN-USB Terminal program. The right picture shows | ||
| + | an alternative set-up. CAN-messages could also be displayed on a LCD. | ||
| + | Important: Follow the instructions given in " | ||
| + | sources! Use the jumper TERM on board 2 to enable the terminating resistance! Use the jumpers JP1 on board 1 and board 2 to power board 2 over the CAN | ||
| + | bus! | ||
| + | Assignment: Use the provided 10-way ribbon cable to connect the two boards. | ||
| + | Make sure to position the connector in the right way, as indicated by a " | ||
| + | board. The red wire has to be connected with the pin marked by " | ||
| + | Use the "Code example for sending a CAN message" | ||
| + | and flash the program into the Atmega32. Use the CAN-USB Terminal program | ||
| + | as described in "How to use the CAN-USB-Terminal" | ||
| + | sage received by board 1. | ||
| + | |||
| + | <code c> | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | int main(void) | ||
| + | { | ||
| + | // insert | ||
| + | while | ||
| + | { | ||
| + | // insert | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====Exercies 2==== | ||
| + | |||
| + | For this exersise you will use the CAN board with the USB_CAN.hex program | ||
| + | (board 1) and a second CAN board (board 2), as in exercise 1. | ||
| + | Assignment: | ||
| + | message. | ||
| + | board 1 to board 2. Create a structure of the type " | ||
| + | Use suitable methods provided by " | ||
| + | " | ||
| + | Use the method " | ||
| + | for LED" to switch on a LED of your choice, depending on the content of the | ||
| + | received message. Make sure to include the header file " | ||
| + | |||
| + | **Example: | ||
| + | switched on. Board 1 sends a CAN message " | ||
| + | switched off. | ||
| + | |||
| + | ====Exercies 3==== | ||
| + | For this exersise you will use two CAN boards, neither of which will be con- | ||
| + | nected to the PC. Simply unplug the USB cable from board 1 and use the AC/DC- | ||
| + | adaptor to power board 1. The boards will stay connected via the ribbon cable. | ||
| + | Board 2 will be powered indirectly over the CAN bus. | ||
| + | |||
| + | **Assignment: | ||
| + | ercise 1, so that it can both send and receive messages. The task is to flash both | ||
| + | boards with the same program and establish communication between them. In | ||
| + | the while-loop of the main-function, | ||
| + | detect if buttons KEY1 or KEY 2 are being pressed. | ||
| + | pull-up resistors on these pins (outside the while-loop). Otherwise the pins will | ||
| + | be " | ||
| + | CANmessage that activates a LED on the other board. If button KEY2 is being | ||
| + | pressed, send a CANmessage that deactivates the same LED on the other board. | ||
| + | |||
| + | **Example: | ||
| + | |||
| + | Board 1 sends a CAN message " | ||
| + | |||
| + | Board 1 sends a CAN message " | ||
| + | |||
| + | Board 2 sends a CAN message " | ||
| + | |||
| + | Board 2 sends a CAN message " | ||