CiA 401 CoIDE example ============================ This is an example application implementing a CANopen CiA 401 device on the STM32F4 Discovery Board. http://www.st.com/stm32f4-discovery http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1848/PF252419 The Discovery board itself does not have a CAN transceiver. To extend it with a CAN transceiver and with a possibility to extend the process IO capabilities and also the possibility to use printf() to watch informal and debug messages, the STM32F4 Discovery Shield is used. http://www.mikroe.com/stm32/stm32f4-discovery-shield/ The CANopen material, including the 401 code, is delivered as a pre-compiled library libCANopenlib401.a. The library is compiled using the same definitions as the application in gen_define.h If you like to extend the application example the restrictions have to be considered. For example: #define CO_NODE_ID 32 only this fixed Node Id can be used /* Definition of numbers of CANopen services */ #define CO_SDO_SERVER_CNT 1u #define CO_PDO_TRANSMIT_CNT 2u #define CO_PDO_RECEIVE_CNT 6u Another restriction is the run time for the use of the CANopen code. It runs little longer than one hour. Some Minutes before stopping, exactly one hour after starting the example, the blue LED on the Discovery board will signal the coming shut down. The object dictionary itself and derived EDS file were generated using the CANopen Device Designer http://www.emtas.de/produkte/canopen-device-designer?lang=en The object dictionary provides enough entries for extending the existing code with process IO code. There is no need to extend it whether direct by changing gen_objdict.c nor by using the Device Designer. The application code is completely visible in the example sources. To handle process inputs and outputs there exist only 4 functions coded in usr_401.c - setting digital out ports as byte - reading digital in ports as byte - writing to analog out converters as 16 bit value - reading from analog digital converters as 16 bit values The function used of the example to set digital outputs is void byte_out_printfInd( UNSIGNED8 port, /**< selected 8bit port */ UNSIGNED16 outVal /**< output value */ ) { printf("digout port:%2d, value:0x%02x, %3d\n", port, outVal, outVal); } and currently outputs the parameters given to the printf() function. The result can be watched if a terminal is connected (1152008N1) to USART2. If the STM32F4 Discovery Shield is extended with one of the Click boards available like "RELAY click" or the "8x8 B click", the byte_out() function can be easily adopted to control these interfaces. The name of the appropriate function used by the CiA401 profile is made known by the event register function coEventRegister_401() in main.c : coEventRegister_401( byte_in_piInd, /* digital in HW API function */ byte_out_printfInd, /* digital out HW API function */ analog_in_piInd, /* the analog in HW API function */ analog_out_printfInd /* analog out HW API function */ ) There are much more so-called indication functions registered to the CANopen stack. All of them are coded in main.c as well. Mostly they are doing nothing than signalling that they are called by sending some text via printf(). As an example, every time the node's network status is changed by a CANopen NMT master the stack calls the registered indication function RET_T nmtInd( BOOL_T execute, CO_NMT_STATE_T newState ) { printf("USR: nmtInd: New Nmt state %d - execute %d\n", newState, execute); return(RET_OK); } We hope to have provided an easy to use and easy to understand example on how to use the CANopen protocol stack. The manuals are available via request to service@emtas.de. Please let us know when you are facing problems. Have fun extending the example. emtas GmbH http://www.emtas.de