Full text
Bachelor’s Thesis Bachelor’s degree in Industrial Technology Engineering CAN FD Node based on a PIC18 Microcontroller REPORT Author: Oriol Garrobé Guilera Director: Manuel Moreno Eguílaz Period: Spring semester Escola Tècnica Superior d’Enginyeria Industrial de Barcelona
Pag. 2 Report
CAN FD Node based on a PIC18 microcontroller Pag. 3 Review This document describes the process to implement a CAN node based on a PIC18 microcontroller and an MCP2517FD click. The system has been programmed using C language. On the first hand, the architecture of the electronic system as well as the CAN FD protocol is explained. Briefly it is shown how the CAN FD frames are, in order to leave it clear for the reader, as the main object of the project is to transfer data through the bus CAN. Therefore, the structure of the data is of great relevance. Also, the architecture of the electronic system as well as its components, both hardware and software, is detailed. On the other hand, it is explained step by step how to implement the system. The PIC18 microcontroller family from Microchip includes an 8 bit CPU, whereas the MCP2517FD CANFD controller is oriented to work with 4 byte word. From this regard, the main issue is to make these two devices compatible. It will be then, a good exercise to show how to link different devices with different bandwidths, with a method that is applicable to any device. Finally, once the implementation is finished, several tests to prove that the system works properly are included. One of the main features of the CAN FD protocol is that it can transfer as well as receive data with different payloads and different baudrates, hence it will be demonstrated that the node is able to process any data frame in any rate set in the CAN FD protocol using a CAN FD sniffer.
Pag. 4 Report Summary REVIEW ______________________________________________________ 3 SUMMARY ____________________________________________________ 4 1. GLOSSARY _______________________________________________ 7 2. PREFACE _________________________________________________ 8 2.1. Origin of the project ............................................................................................ 8 2.2. Motivation ........................................................................................................... 8 2.3. Previous requirements ....................................................................................... 8 3. INTRODUCTION___________________________________________ 10 3.1. Objectives of the project................................................................................... 10 3.2. Scope of the project ......................................................................................... 10 4. SYSTEM _________________________________________________ 11 4.1. CAN PROTOCOL ............................................................................................ 11 4.1.1. CONTROLLER AREA NETWORK .................................................................... 11 4.1.1.1. Physical layer – Architecture ................................................................... 11 4.1.1.2. Error detection ......................................................................................... 12 4.1.2. Control Area Network with Flexible Data-Rate ................................................... 12 4.1.3. CAN Vs. CAN FD ................................................................................................ 13 4.2. MCP2517FD CLICK......................................................................................... 15 4.2.1. External CAN FD Controller with SPI Interface. ................................................. 15 4.2.2. ATA6563 CAN Transceiver................................................................................. 16 4.2.3. Used pins ............................................................................................................. 16 4.3. PIC18F4520 ..................................................................................................... 17 4.4. MPLAB C COMPILER FOR PIC18 MCUs ...................................................... 18 4.5. ARCHITECTURE OF THE SYSTEM .............................................................. 19 5. PROJECT ________________________________________________ 21 5.1. DRIVER DEVELOPMENT ............................................................................... 21 5.1.1. Needed files......................................................................................................... 21 5.1.2. Data types ........................................................................................................... 21 5.1.3. Declaring local variables ..................................................................................... 22 5.1.4. Splitting the message .......................................................................................... 23 5.1.5. New SPI ............................................................................................................... 24
CAN FD Node based on a PIC18 microcontroller Pag. 5 5.1.6. Memory usage ..................................................................................................... 25 5.1.7. SPI instructions .................................................................................................... 25 5.1.8. Linking structs and unions ................................................................................... 27 5.1.8.1. Union data type........................................................................................ 28 5.1.8.2. Structure data type .................................................................................. 29 6. RESULTS ________________________________________________ 31 6.1. SPI INSTRUCTIONS TESTS .......................................................................... 31 6.1.1. Test WriteByte & ReadByte ................................................................................ 31 6.1.2. Test WriteByte & ReadWord ............................................................................... 32 6.1.3. Test WriteWord & ReadWord ............................................................................. 33 6.1.4. Test WriteHalfWord & ReadHalfWord ................................................................ 34 6.1.5. Test WriteHalfWord & ReadWord ...................................................................... 35 6.1.6. Test WriteByteArray & ReadByteArray ............................................................... 36 6.1.7. Test WriteWordArray & ReadWordArray ........................................................... 39 6.2. CAN TESTS ..................................................................................................... 41 6.2.1. CONFIGURATION............................................................................................... 41 6.2.1.1. Reset ........................................................................................................ 41 6.2.1.2. Initialize RAM ........................................................................................... 41 6.2.1.3. CAN configuration ................................................................................... 41 6.2.1.4. Set up TX and Rx FIFOs ......................................................................... 41 6.2.1.5. Filter & Mask ............................................................................................ 41 6.2.1.6. Bit time ..................................................................................................... 42 6.2.1.7. Select mode ............................................................................................. 42 6.2.2. LoopBack mode tests .......................................................................................... 45 6.2.2.1. Test 1 ....................................................................................................... 46 6.2.2.2. Test 2 ....................................................................................................... 47 6.2.2.3. Test 3 ....................................................................................................... 49 6.2.2.4. Test 4 ....................................................................................................... 51 6.2.2.5. Test 5 ....................................................................................................... 55 6.2.2.6. Test 6 ....................................................................................................... 56 6.2.3. Normal mode tests with CAN sniffer ................................................................... 57 6.2.3.1. Test 1 ....................................................................................................... 58
Pag. 6 Report 6.2.3.2. Test 2 ....................................................................................................... 60 6.2.3.3. Test 3 ....................................................................................................... 62 6.2.3.4. Test 4 ....................................................................................................... 64 6.2.3.5. Test 5 ....................................................................................................... 66 6.2.3.6. Test 6 ....................................................................................................... 68 6.2.3.7. Test 7 ....................................................................................................... 70 6.2.3.8. Test 8 ....................................................................................................... 73 6.2.3.9. Test 9 ....................................................................................................... 75 6.2.3.10. Test 10 ................................................................................................. 77 6.2.3.11. Test 11 ................................................................................................. 79 6.2.3.12. Test 12 ................................................................................................. 82 6.2.3.13. Test 13 ................................................................................................. 83 CONCLUSIONS AND FUTURE WORK _____________________________ 84 THANKS _____________________________________________________ 85 BIBLIOGRAPHY _______________________________________________ 86 Bibliographic references ............................................................................................ 86 ANNEX ______________________________________________________ 88 A.1. API FUNCTIONS ................................................................................................ 88
CAN FD Node based on a PIC18 microcontroller Pag. 7 1. Glossary CAN: Controller Area Network. CPU: Central Processing Unit. CANFD: Controller Area Network with Flexible Data-rate. IDE: Integrated Development Environment. MCU: Microcontroller Unit.
Pag. 8 Report 2. Preface 2.1. Origin of the project The CAN (Controller Area Network) protocol - designed by Robert Bosch GmbH in 1983 [1] - is a method of communication between various electronic devices. CAN provides a mechanism which is incorporated in the hardware and the software so different devices can communicate with each other using a common cable with two copper wires. In 2011, Bosch invented the CAN FD (flexible data-rate), which improves the classical CAN [2]. It is possible to transmit data faster than with 1 Mbit/s and the payload (data field) is now up to 64 bytes long and not limited to 8 bytes anymore. From this regard, it is of great relevance to understand how this new protocol works and be able to develop a low-cost node that eventually could be used in a real CAN FD network. 2.2. Motivation This project was chosen because of the following reasons. In the first place, I wanted to do a project where I could work with software. I want to improve my skills in this field, and this was a good opportunity to learn a new programming language. From this regard, the subjects related to electrical and electronic engineering are the ones that I enjoyed the most. That is why I chose a project in electronics, so I could see how working in this field could be. Finally, I would like to work in the automotive industry. The CAN bus is widely used in the automotive and aerospace industries and the CAN FD is a current extension to the original CAN. Therefore, this project gathered all my interests, and because of that I took it. 2.3. Previous requirements In order to be able to develop the project it was necessary to have knowledge about the following topics.
CAN FD Node based on a PIC18 microcontroller Pag. 9 On the one hand, knowing how a digital system works and its structure. The elements that compound the system and which their function is. Which the steps that any digital system follows to achieve their purpose are. More specifically, it was necessary to understand the CAN FD protocol. On the other hand, to be able to modify the functions of the system, it was necessary to program C language. That is why before starting the project I completed a course in Tutorialspoint.com [3] about C language.
Pag. 16 Report • Oscillator. It generates the Clock. • Internal LDO and POR circuit. • The I/O control. Fig. 6. Module block diagram. Source: [8]. 4.2.2. ATA6563 CAN Transceiver The ATA6563 [11] is a high-speed CAN transceiver that provides an interface between a controller area network (CAN) protocol controller and the physical two-wire CAN bus. It is designed for high-speed applications in the automotive industry, providing differential transmit and receive capability to a CAN protocol controller. It offers improved electromagnetic compatibility (EMC) and electrostatic discharge (ESD) performance and has an ideal behaviour to the CAN when the supply voltage is off. 4.2.3. Used pins For this project only the following pins of the MCP2517FD Click are used. Pin name Description GND Ground. 5V Positive supply.
CAN FD Node based on a PIC18 microcontroller Pag. 17 3V3 Positive supply. SDI SPI data input. SDO SPI data output. SCK Spi clock input. nCS SPI chip select input. Table 1. Used pins of the MCP2517FD Click. Source: [12]. 4.3. PIC18F4520 The PIC18F4520 microcontroller - in this case in a 40 pin PDIP package - is an 8-bit enhanced flash PIC microcontroller that comes with nanoWatt technology and is based on RISC architecture [13]. It comes with unbuilt peripheral with the ability to perform multiple functions. The PIC18F4520 contains 256 bytes of EEPROM data memory, 1536 bytes of RAM, and program memory of 32K. It also incorporates 2 Comparators,10-bit Analog-to-Digital (A/D) converter with 13 channels and houses decent memory endurance around 1,000,000 for EEPROM and 100,000 for program memory. Every pin on the module comes with a unique function, used as per the requirement of the project, and some pins incorporate multiple functions [13]. In this project the following pins are used: PIN Features Pin 14: RC3/SCK/SCL. RC3. Digital I/O. SCK. Synchronous serial clock Input/Output for SPI Mode. SCL. Synchronous serial clock Input/Output for IC Mode. Pin 15: RC4/SDI/SDA. RC4. Digital I/O. SDI. SPI data in. SDA. IC data I/O.
Pag. 18 Report Pin 16: RC5/SDO. RC5. Digital I/O. SDO. SPI data out. Pin 21: RB0/INT0/FLT0/AN12. RB0. Digital I/O. INT0. External interrupt 0. FLT0. PWM Fault input for CCP1. AN12. Analog input 12. Table 2. PIN features. Source: [13]. It is important for the project to emphasize that it is a microcontroller with an 8 bit CPU. The PIC18F4520 can perform many functions, among them, the In-circuit serial programming (ICSP), also called In-system programming (ISP), makes the device enable to be programmed in the required system after installation, setting it free from programming the device before making it compatible with the certain project. Microchip provides for free its own standard compiler for the PIC controller family called MPLAB C compiler for PIC18 MCUsknown as C18 Compiler – which is explained in section 4.4. The PIC18F4520 is a good choice for a university project due the following features: • It has a user-friendly interface that requires no prior skills. • It can perform many functions with the minimum circuitry. • It is cheap. • Minimum power consumption. 4.4. MPLAB C COMPILER FOR PIC18 MCUs The MPLAB C18 is a C compiler used for the PIC18 family of PICMicro 8-bit MCUs [14]. It is a component of Microchip’s MPLAB Integrated Development Environment (IDE) - providing a full graphical front end - for easy-to-use source level debugging with MPLAB’s
CAN FD Node based on a PIC18 microcontroller Pag. 19 software and hardware debug engines. Text errors in source code and breakpoints instantly switch to corresponding lines in the proper file, and watch windows show data structures with defined data types, including floating points, arrays and structures. Among its features is important to highlight the following: • It is compatible with ANSI ‘89. • Compatibility with object modules generated by the MPASM assembler, allowing complete freedom in mixing assembly and C programming in a single project. • Transparent read/write access to external memory. • Strong support for inline assembly when total control is necessary. • efficient code generator engine with multi-level optimization. • Extensive library support, including PWM, SPI, I2C, UART, USART, string manipulation and math libraries. • Full user-level control over data and code memory allocation. • Supports both a small (16-bit pointers) and a large (24-bit pointers) memory model for efficient use of memory. • MPLIB allows easy use of included libraries and for user created libraries. • Extensive multi-pass optimizations. • Supports new PIC18F extended mode instructions. 4.5. ARCHITECTURE OF THE SYSTEM Using all hardware and software elements explained before, the architecture of the system is showed up next. In the first place, the computer where the Driver is developed is connected to the PIC18 through the MPLAB ICD 3 [15] and the Wave Share PIC18 development board [16]. (see Fig.7).
Pag. 20 Report Figure 7. Computer connected to the node through the MPLAB ICD 3. Source: Own. The next step is to connect the PIC18 to the MCP2517FD click using the PINs mentioned in section 4.2 and section 4.3. (see Fig.8). Figure 8. PIC18 connected to the MCP2517FD. Source: Own. Finally, the MCP2517FD can be connected to a real CAN FD network. However, for the moment it will not - as the project can be developed and tested without the needs of a real network.
CAN FD Node based on a PIC18 microcontroller Pag. 21 5. PROJECT 5.1. DRIVER DEVELOPMENT 5.1.1. Needed files The development of the driver for this project is based on an existing solution from Microchip [16]. The source code that is used in this project is a variation of the MCP2517FD canfdspi API for a PIC32MX470 [17]. The PIC32MX470 is a 32-bit development platform, so the first step was to make possible that the PIC18 could process this code. In first place, it is necessary to import all the needed files, which are the following: Header files Source files drv_canfdspi_api.h drv_canfdspi_defines.h drv_canfdspi_register.h drv_canfdspi_spi.h main.h drv_canfdspi_api.c drv_spi.c main.c Table 3. Used files. Source: [17]. Also, as the code is inherited, there are files that are not necessary for the project. These files, however, are imported in the original code. The next step is then to erase those files and comment the lines where they were imported in order to remove possible compiler errors. 5.1.2. Data types Once the MPLAB IDE and the compiler C18 are installed, using the debugging tool MPLAB ICD3 it is proceeded to adapt the code. The first step to adapt the code – using the debugging tool MPLAB ICD3 - is to define the data types - as the PIC18 defines them differently than the PIC32 - with the following order.
Pag. 22 Report Original code Modified code None #define uint32_t unsigned long #define uint16_t unsigned int #define uint8_t unsigned char #define int8_t char #define bool unsigned char Table 4. Data types definition. Source: own. These data types are defined in the “drv_canfdspi_defines.h” file, and then imported in the other files of the project with the following order: #include “drv_canfdspi_defines.h” 5.1.3. Declaring local variables Using this compiler, it is mandatory that all the local variables are defined at the very beginning of the function – to avoid a syntax error -. The next step is, then, to move relocate local variables definitions. One example of this procedure is shown next: Original code Modified code int8_t DRV_CANFDSPI_RamInit(CANFDSPI_MODULE_ID index, uint8_t d) { uint8_t txd[SPI_DEFAULT_BUFFER_LENGTH]; uint32_t k; int8_t spiTransferError = 0; // Prepare data for (k = 0; k < SPI_DEFAULT_BUFFER_LENGTH; k++) { txd[k] = d; } uint16_t a = cRAMADDR_START; for (k = 0; k < (cRAM_SIZE / SPI_DEFAULT_BUFFER_LENGTH); k++) { int8_t DRV_CANFDSPI_RamInit(CANFDSPI_MODULE_ID index, uint8_t d) { uint8_t txd[SPI_DEFAULT_BUFFER_LENGTH]; uint32_t k; int8_t spiTransferError = 0; uint16_t a = cRAMADDR_START; // Prepare data for (k = 0; k < SPI_DEFAULT_BUFFER_LENGTH; k++) { txd[k] = d; } for (k = 0; k < (cRAM_SIZE / SPI_DEFAULT_BUFFER_LENGTH); k++) {
CAN FD Node based on a PIC18 microcontroller Pag. 23 spiTransferError = DRV_CANFDSPI_WriteByteArray(index, a, txd, SPI_DEFAULT_BUFFER_LENGTH); if (spiTransferError) { return -1; } a += SPI_DEFAULT_BUFFER_LENGTH; } return spiTransferError; } spiTransferError = DRV_CANFDSPI_WriteByteArray(index, a, txd, SPI_DEFAULT_BUFFER_LENGTH); if (spiTransferError) { return -1; } a += SPI_DEFAULT_BUFFER_LENGTH; } return spiTransferError; } Table 5. Local variables declaration. Source: own. It can be seen that “uint16_t a = cRAMADDR_START;” is replaced at the top of the function. 5.1.4. Splitting the message One of the biggest issues of the project is that the original code is written for a 32-bit microcontroller, while an 8-bit MCU is used in this project. Therefore, it is necessary first to split the structures in members no bigger than 1 byte, provided that the maximum length of the field is less than or equal to the integer word length of the microcontroller. In the first place, in the “drv_canfdspi_defines.h” there are structure data types that contained bit fields with widths greater than 8 bits. Such bit fields must be split as explained before, so they can fit in the MCU memory. Following, an example of this procedure is shown: Original code Modified code typedef struct _CAN_FILTEROBJ_ID { uint32_t SID : 11; uint32_t EID : 18; uint32_t SID1 : 1; uint32_t EXIDE : 1; uint32_t unimplemented1 : 1; } CAN_FILTEROBJ_ID; typedef struct _CAN_FILTEROBJ_ID { uint32_t SIDA : 8; uint32_t SIDB : 3; uint32_t EIDA : 8; uint32_t EIDB : 8; uint32_t EIDC : 2; uint32_t SID1 : 1; uint32_t EXIDE : 1; uint32_t unimplemented1 : 1; } CAN_FILTEROBJ_ID; Table 6. Structure type modification example. Source: own. This problem is present also in the “drv_canfdspi_register.h” file. In this case it is in union data
Pag. 24 Report types that define the architecture of the registers. The procedure used to split the register is the following: Original code Modified code typedef union _REG_CiFIFOUA { struct { uint32_t UserAddress : 12; uint32_t unimplemented1 : 20; } bF; uint32_t word; uint8_t byte[4]; } REG_CiFIFOUA; typedef union _REG_CiFIFOUA { struct { uint32_t UserAddress1 : 8; uint32_t UserAddress2 : 4; uint32_t unimplemented11 : 8; uint32_t unimplemented12 : 8; uint32_t unimplemented13 : 4; } bF; uint32_t word; uint8_t byte[4]; } REG_CiFIFOUA; Table 7. Union type modification example. Source: Own. In both cases now the message fits the Microchip PIC18. Applying these changes to both the header code and the source code, the compiler does show no more errors. This does not mean that the function of the code is the proper one, this only means that the microcontroller understands the code. 5.1.5. New SPI The SPI driver used for the PIC32 is indeed too advanced. Therefore, a simpler one is enough for the PIC18 – based on the C18 libraries [18]. Since there is only one SPI peripheral in the MCU there is no need to index which one the SPI is transferring to. From these regards, we must assign the values 0 or 1 – 1 meaning that we are accessing at the SPI - with the SPI function “SPI_CS” to access the RAM. To initialize the SPI it is only necessary to use the function “OpenSPI” from the C18 libraries. To transfer data, “WriteSPI” and “ReadSPI” functions are used and the code that assigns the slave index – as there is only one slave - is erased.
CAN FD Node based on a PIC18 microcontroller Pag. 25 5.1.6. Memory usage When trying to export the code to the PIC18, there was not enough ROM/RAM memory to fit it all. It was then necessary to take two actions to get enough space to implement the “main.c” afterwards. The first step was to save some files at the ROM (Read Only Memory) in order to free space from the RAM (Random Access Memory). The second step to solve the memory problem was to erase all the functions from the API that were not working. This means all the functions in the original code that were not necessary for the project were erased or commented. The API functions needed for this project are enumerated and described in Annex 1. The result was that enough space to develop the “main.c” was found. 5.1.7. SPI instructions The SPI instructions are the ones that access the SFRs and the RAM. The SFRs are the Special Function Registers and are used to control and read the status of the CAN FD Controller module. The RAM – Random Access Memory – is used to store the data of the message objects. To read and write through the SPI is necessary to use the transfer data functions set in the SPI. For this, it is necessary to modify the following functions. The “ReadSPI” and the “WriteSPI” are the functions from the SPI that are going to be called when using the SPI instructions. To access the SFRs it is necessary that the device is in Configuration mode. On the other hand, the RAM is word oriented (4 bytes at a time), so any multiple of 4 data bytes can be read or written in one instruction. Each SPI instruction starts by driving the nCS (Chip Select) low – from the value 1 to 0 -. The 4-bit command and the 12-bit address are shifted into the SDI. During a write instruction databits are shifted into the SDI on the rising edge of SCK. On the contrary, data bits are shifted out of the SDO on the falling edge. Briefly, it is necessary to force the nCS low (0) at the beginning of every instruction and rising it back at the end of it. All the SPI instructions have been modified in order to fulfil this
Pag. 32 Report Results: Figure 8. Results of the WriteByte & ReadByte test. Source: Own. As expected, Figure 8 shows that the value of the variable “value” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly. 6.1.2. Test WriteByte & ReadWord Using the code shown in Figure 9, the following SPI instructions are tested: • DRV_CANFDSPI_Reset • DRV_CANFDSPI_WriteByte • DRV_CANFDSPI_ReadWord Figure 9. WriteByte & ReadWord test code. Source: Own.
CAN FD Node based on a PIC18 microcontroller Pag. 33 Results: Figure 10. Results of the WriteByte & ReadWord test. Source: Own. As expected, Figure 10 shows that the value of the variable “value” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly. 6.1.3. Test WriteWord & ReadWord Using the code shown in Figure 11, the following SPI instructions are tested: • DRV_CANFDSPI_WriteWord • DRV_CANFDSPI_ReadWord Figure 11. WriteWord & ReadWord test code. Source: Own.
Pag. 34 Report Results: Figure 12. Results of the WriteWord & ReadWord test. Source: Own. As expected, Figure 12 shows that the value of the variable “value” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly. 6.1.4. Test WriteHalfWord & ReadHalfWord Using the code shown in Figure 13, the following SPI instructions are tested: • DRV_CANFDSPI_WriteHalfWord • DRV_CANFDSPI_ReadHalfWord Figure 13. WriteHalfWord & ReadHalfWord test code. Source: Own.
CAN FD Node based on a PIC18 microcontroller Pag. 35 Results: Figure 14. Results of the WriteHalfWord & ReadHalfWord test. Source: Own. As expected, Figure 14 shows that the value of the variable “value” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly. 6.1.5. Test WriteHalfWord & ReadWord Using the code shown in Figure 15, the following SPI instructions are tested: • DRV_CANFDSPI_WriteHalfWord • DRV_CANFDSPI_ReadWord Figure 15. WriteHalfWord & ReadWord test code. Source: Own.
Pag. 36 Report Results: Figure 16. Results of the WriteHalfWord & ReadWord test. Source: Own. As expected, Figure 16 shows that the value of the variable “value” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly. 6.1.6. Test WriteByteArray & ReadByteArray Using the code shown in Figure 17, the following SPI instructions are tested: • DRV_CANFDSPI_WriteByteArray • DRV_CANFDSPI_ReadByteArray
CAN FD Node based on a PIC18 microcontroller Pag. 37 Figure 17. WriteByteArray & ReadByteArray test code. Source: Own.
Pag. 38 Report Results: Figure 18. Results of the WriteByteArray & ReadByteArray test. Source: Own. As expected, Figure 18 shows that the value of the variable “rxd” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly.
CAN FD Node based on a PIC18 microcontroller Pag. 39 6.1.7. Test WriteWordArray & ReadWordArray Using the code shown in Figure 19, the following SPI instructions are tested: • DRV_CANFDSPI_WriteWordArray • DRV_CANFDSPI_ReadWordArray Figure 19. WriteByteArray & ReadByteArray test code. Source: Own.
Pag. 40 Report Results: Figure 20. Results of the WriteWordArray & ReadWordArray test. As expected, Figure 20 shows that the value of the variable “rxd” – read by the reading functionis the written before in the same address. Therefore, these functions do work properly.
CAN FD Node based on a PIC18 microcontroller Pag. 41 6.2. CAN TESTS 6.2.1. CONFIGURATION The CAN FD controller module needs to be configured to run its functions properly. The following fields need to be set. In order to do so – aside from some mentioned occasionsit is necessary to be in configuration mode. The CANFD controller configuration is implemented in the “main.c” file. 6.2.1.1. Reset The MCP2517FD should be reset to its initial values. This prevents the system to use any previously set value that makes the system work in a different way. By doing this, the MCP2517FD is set in Configuration mode. While in this mode, the system does not access the CAN, therefore it is not likely that the device disturbs the bus. Also, it is necessary that the system is in Configuration mode in order to configure some features of the system, such as the FIFOS or the oscillator. 6.2.1.2. Initialize RAM It is necessary to initialize the RAM and fill it with any chosen value. 6.2.1.3. CAN configuration The module supports ISO CRC and non-ISO CRC. It is necessary to enable or not this feature by setting the ISOCREN bit. If preferred, RAM space must be reserved for the TEF and the TXQ by setting the STEF and TXQEN bits, respectively. 6.2.1.4. Set up TX and Rx FIFOs The message objects of the Transmit and Receive FIFOs are in the RAM. Therefore, the application must configure the number and the payload size of the message objects inside each FIFO. The location of the objects in the RAM is determined by this configuration. 6.2.1.5. Filter & Mask In order to set the Filter and Mask values, it is necessary to disable the filter first. It is not necessary though to be in configuration mode. When the object of the filter is set, it must be linked to the FIFO where the matching receive will be stored.
Pag. 48 Report Results: Figure 22. Test 2 results. As expected, Figure 22 shows that the value of the variable “rxd” – received messageis the same as the “txd” – sent message-. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 49 6.2.2.3. Test 3 Table 16 shows the variable values that will be used for the Test 3. Variable Value DLC 32 Txd[i] Random Tx FIFO size 8 Rx FIFO size 1 IDE 0x400 Mask None Filter None Table 16. Test 3 variable values. Source: Own. Results: Figure 23. Test 3 results. Source: Own.
Pag. 50 Report Figure 24. Test 3 results. Source: Own. As expected, Figures 23 and 24 show that the value of the variable “rxd” – received messageis the same as the “txd” – sent message-. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 51 6.2.2.4. Test 4 Table 17 shows the variable values that will be used for the Test 4. Variable Value DLC 64 Txd[i] 64-i Tx FIFO size 1 Rx FIFO size 16 IDE 0x500 Mask None Filter None Table 17. Test 4 variable values. Source: Own. Results: Figure 25. Test 4 results. Source: Own.
Pag. 52 Report Figure 26. Test 4 results. Source: Own.
CAN FD Node based on a PIC18 microcontroller Pag. 53 Figure 27. Test 4 results. Source: Own.
Pag. 54 Report Figure 28. Test 4 results. Source: Own. As expected, Figures 25, 26, 27 and 28 show that the value of the variable “rxd” – received messageis the same as the “txd” – sent message-. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 55 6.2.2.5. Test 5 Table 18 shows the variable values that will be used for the Test 5. Variable Value DLC 32 Txd[i] 0x99 Tx FIFO size 8 Rx FIFO size 8 IDE 0x500 Mask None Filter 0x300 Table 18. Test 5 variable values. Source: Own. Results: As expected, as the filter only allow the messages with the 0x500 identifier, there is no message received. Therefore, the system works properly.
Pag. 56 Report 6.2.2.6. Test 6 Table 19 shows the variable values that will be used for the Test 6. Variable Value DLC 32 Txd[i] 0x0A Tx FIFO size 16 Rx FIFO size 1 IDE 0x300 Mask 0xff Filter None Table 19. Test 6 variable values. Source: Own. Results: As expected, with the set mask, no messages get through, there are no messages received. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 57 6.2.3. Normal mode tests with CAN sniffer Once it is proven that the system works properly using the LoopBack mode, it is possible to switch to the CANFD normal mode and send and receive messages through a real CANFD network. In order to have evidence of the good functioning of the system, a CANFD sniffer is used. Through this sniffer, message objects will be sent and received, and therefore, if the results are the expected, it can be concluded that the system develops its function properly. It will also be checked on the oscilloscope that the voltage levels are correct. On the oscilloscope it will be visible both the CAN HIGH and the CAN LOW. By doing this, the CAN FD frame will be clearly visible. When using the sniffer, it will also be modified the arbitration and data bit time. The tests will follow the same pattern used for the LoopBack mode tests. In the Figure 29 it can be seen the CAN FD node connected to the CAN FD sniffer. Figure 29. Assembling of the system. Source: Own. Following there are several tests using the CANFD Normal mode and the CANFD sniffer.
Pag. 64 Report 6.2.3.4. Test 4 Table 23 shows the variable values that will be used for the Test 4. Variable Value DLC 64 Txd[i] 0x99 Tx FIFO size 1 Rx FIFO size 16 IDE 0x500 Mask None Filter None Table 23. Test 4 variable values. Source: Own. In Figure 36 it can be clearly seen the CAN FD frame. Also, the differences of speeds between the arbitration zone and the payload zone. There is a payload of 64 bytes. Figure 36. Test 4 voltage levels. Source: Own. Results: In Figure 37 it can be seen that the message sent through the real CAN FD network is the expected. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 65 Figure 37. Test 4 results.
Pag. 66 Report 6.2.3.5. Test 5 Table 24 shows the variable values that will be used for the Test 5. Variable Value DLC 32 Txd[i] 0xA0 + 2*i Tx FIFO size Random Rx FIFO size Random IDE Random Mask None Filter None Arbitration bit time 250 kbit/s Data bit time 1 Mbit/s Table 24. Test 5 variable values. Source: Own. Results: In Figure 38 it can be seen that the message sent through the real CAN FD network is the expected. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 67 Figure 38. Test 5 results.
Pag. 68 Report 6.2.3.6. Test 6 Table 25 shows the variable values that will be used for the Test 6. Variable Value DLC 48 Txd[i] Random Tx FIFO size Random Rx FIFO size Random IDE 0x402 Mask None Filter None Arbitration bit time 250 kbit/s Data bit time 2 Mbit/s Table 25. Test 6 variable values. Source: Own. Results: In Figure 39 it can be seen that the message sent through the real CAN FD network is the expected. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 69 Figure 39. Test 6 results.
Pag. 70 Report 6.2.3.7. Test 7 Table 26 shows the variable values that will be used for the Test 7. Variable Value DLC 64 Txd[i] Figure 40 Tx FIFO size 8 Rx FIFO size 8 IDE 0x500 Mask None Filter None Arbitration bit time 250 kbit/s Data bit time 4 Mbit/s Table 26. Test 7 variable values. Source: Own. Message sent: Figure 40. Message sent with the CAN FD sniffer. Source: Own. Results: In Figures 41 and 42 it can be seen that the message received through the real CAN FD network is the expected. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 71 Figure 41. Test 7 results.
Pag. 72 Report Figure 42. Test 7 results.
CAN FD Node based on a PIC18 microcontroller Pag. 73 6.2.3.8. Test 8 Table 27 shows the variable values that will be used for the Test 8. Variable Value DLC 16 Txd[i] Figure 43 Tx FIFO size 1 Rx FIFO size 1 IDE 0x500 Mask None Filter None Arbitration bit time 250 kbit/s Data bit time 2 Mbit/s Table 27. Test 8 variable values. Message sent: Figure 43. Message sent with the CAN FD sniffer. Source: Own. Results: In Figure 44 it can be seen that the message received through the real CAN FD network is the expected. Therefore, the system works properly.
Pag. 80 Report Figure 50. Test 11 results.
CAN FD Node based on a PIC18 microcontroller Pag. 81 Figure 51. Test 11 results.
Pag. 82 Report 6.2.3.12. Test 12 Table 31 shows the variable values that will be used for the Test 12. Variable Value DLC 64 Txd[i] Figure 51 Tx FIFO size 16 Rx FIFO size 16 IDE 0x400 Mask None Filter 0x300 Arbitration bit time 250 kbit/s Data bit time 2 Mbit/s Table 31. Test 12 variable values. Source: Own. Message sent: Figure 51. Message sent with the CAN FD sniffer. Source: Own. Results: As expected, as the filter only allow the messages with the 0x300 identifier, there are no messages received. Therefore, the system works properly.
CAN FD Node based on a PIC18 microcontroller Pag. 83 6.2.3.13. Test 13 Table 31 shows the variable values that will be used for the Test 13. Variable Value DLC 64 Txd[i] Figure 52 Tx FIFO size 16 Rx FIFO size 16 IDE 0x400 Mask 0xff Filter Random Arbitration bit time 250 kbit/s Data bit time 2 Mbit/s Table 31. Test 13 variable values. Source: Own. Message sent: Figure 52. Message sent with the CAN FD sniffer. Source: Own. Results: As expected, with the set mask, no messages get through, there are no messages received. Therefore, the system works properly.
Pag. 84 Report Conclusions and future work As a conclusion it can be said that the main objective of the project has been achieved. It has been successfully developed a CAN FD node that can transmit - send and receive - data through a real CAN network. Nevertheless, the node can be improved as this is the first version that only performs the most basic functions. In order to improve the project, and as a future work, some features of the CAN FD node based on a PIC18 microcontroller could be improved, which are the following: • In the first place in this project - as commented in section 3.2 - it has only been used the data transmission through transmit and receive FIFOs. One point to improve, then, would be to use also the Transmit Event FIFOs (TEF) and the Transmit and Receive Queue (TxQ & RxQ), which would make the system more thorough [12]. • In the second place it could be interesting to add interrupts, as the CAN protocol is known by its error-detecting reliability and this would improve this feature. • Also, it is possible with the used devices to introduce an error-detecting code called Cyclic Redundancy Check (CRC). This code reassures that the system functions properly and that there are no errors in the data transmission. • Finally, in this project only two modes have been mentioned - CAN Normal mode and CAN LoopBack mode-. The MCP2517FD click allow several other modes, therefore implementing such modes could make the CAN FD node more efficient. Briefly, the main objective has been successfully accomplished and those derived objectives that, even though are not that visible, have a huge impact to the project - such as understanding the CAN protocol, the insights of the MPLAB or coding in C - have also been surpassed.
CAN FD Node based on a PIC18 microcontroller Pag. 85 Thanks I would like to thank the great support and guidance that the supervisor of the project Manuel Moreno Eguílaz has given me. He has been always available to help me get through any issue that I found. I would also like to thank all the professors that I have had during the degree, as they taught me the knowledge that I required to develop this project. Finally, I also would like to thank my family and friends to offer me the support needed to get through the degree, without them it would have been way more difficult and less enjoyable.
Pag. 86 Report Bibliography Bibliographic references [1] DEAR BORN GROUP, INC. CAN: Controller Area Network, Introduction and primer. 27077 Hills Tech Court, Farmington Hills, September 2004. [https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=8&ved=2ahUKE wjS3pW2ovHeAhVIAcAKHawaBkQQFjAHegQIBxAC&url=https%3A%2F%2Fspaces.u su.edu%2Fdownload%2Fattachments%2F53053449%2Fprimer.pdf%3Fversion%3D1 %26modificationDate%3D1366417485000%26api%3Dv2&usg=AOvVaw3RQkvICuqs0DTs59QCYdB, 13th February 2019]. [2] ROBERT BOSCH Gmbh: CAN FD Specification version 1.0. Gerlingen, Germany, April 2012. [file:///C:/Users/Oriol/Downloads/can_fd_spec%20(1).pdf, 23rd February 2019]. [3] TUTORIALS POINT, C programming tutorial [ https://www.tutorialspoint.com/cprogramming/index.htm, 20th February 2019]. [4] PICOTECH, CAN and CAN FD bus decoding. [https://www.picotech.com/library/oscilloscopes/can-bus-serial-protocol-decoding, 23rd May 2019]. [5] WIKIPEDIA COMMONS, CAN-Frame mit Pegeln mit Stuffbits. [https://commons.wikimedia.org/wiki/File:CAN-Frame_mit_Pegeln_mit_Stuffbits.svg, 12th April 2019] [6] CAN IN AUTOMATION, CAN FD, the basic idea. [https://www.can-cia.org/canknowledge/can/can-fd/, 12th April 2019]. [7] KENT LENNARTSSON – KVASER, Comparing CAN FD with Classical CAN. [https://www.kvaser.com/wp-content/uploads/2016/10/comparing-can-fd-with-classicalcan.pdf, 13th February 2019]. [8] MICROCHIP TECHNOLOGY INC, MCP25XXFD Reference Manual [http://ww1.microchip.com/downloads/en/DeviceDoc/MCP25XXFD-FRM,-CAN-FDController-Module-DS20005678D.pdf, 17th April 2019]. [9] MIKROE EMBEDDED TOOLS, MCP2517FD Click. [https://www.mikroe.com/mcp2517fd-click, 10th June 2019]
CAN FD Node based on a PIC18 microcontroller Pag. 87 [10] INTERNATIONAL STANDARD, ISO 11898-1 Road Vehicles [https://www.sis.se/api/document/preview/919965/, 10th June 2019]. [11] ATMEL, ATA6560/ATA6561 Datasheet. [https://download.mikroe.com/documents/datasheets/ata6563-datasheet.pdf, 10th June 2019]. [12] MICROCHIP, External CAN FD Controller with SPI Interface Datasheet.[ http://ww1.microchip.com/downloads/en/DeviceDoc/MCP2517FD-External-CAN-FDController-with-SPI-Interface-20005688B.pdf, 13th February 2019]. [13] MICROCHIP, PIC18F4520 Datasheet. [https://ww1.microchip.com/downloads/en/devicedoc/39631a.pdf. 13th February 2019]. [14] MICROCHIP, MPLAB X Integrated Development Environment. [https://www.microchip.com/mplab/mplab-x-ide, 20th March 2019]. [15] MICROCHIP, MPLAB ICD 3 In-Circuit Debugger. [https://www.microchip.com/developmenttools/ProductDetails/dv164035, 18th June 2019]. [16] WAVE SHARE, OPEN18F4520 Standard PIC Development Board Datasheet. [https://www.waveshare.com/wiki/Microchip_Datasheets#PIC18F4_Series, 18th June 2019]. [17] MICROCHIP, Firmware Drivers. [https://www.microchip.com/wwwproducts/en/MCP2517FD, 13th February 2019]. [18] MICROCHIP, MPLAB C18 C Compiler Libraries. [http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_C18_Libraries_51297c.pd f, 28TH March 2019].
Pag. 88 Report Annex A.1. API FUNCTIONS DRV_CANFDSPI_Reset Resets internal registers to default state. Sintax int8_t DRV_CANFDSPI_Reset(CANFDSPI_MODULE_ID index) Parameters 0 Return values 0 Precondition None. Side effects Selects Configuration mode. Exemple DRV_CANFDSPI_Reset(0)
CAN FD Node based on a PIC18 microcontroller Pag. 89 DRV_CANFDSPI_ReadByte Reads one byte from SFR address. Sintax int8_t DRV_CANFDSPI_ReadByte(CANFDSPI_MODULE_ID index, uint16_t address, uint8_t *rxd) Parameters Index = 0 Address = Any readable/writable SFR. For example, 0x010 *rxd = Any variable. For example, &value Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_ReadByte(0, address, &value)
Pag. 96 Report DRV_CANFDSPI_WriteByteArray Writes an array of bytes to RAM address. Sintax int8_t DRV_CANFDSPI_WriteByteArray(CANFDSPI_MODULE_ID index, uint16_t address, uint8_t *txd, uint16_t nBytes); Parameters Index = 0 Address = Any readable/writable RAM. For example, 0x400 *txd = Array minimum of four bytes. For example ip[4] = {0x01,0x44,0x33,0x55} nBytes = number of bytes to write. Must be multiple of four. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_WriteByteArray(0, address, ip, 4);
CAN FD Node based on a PIC18 microcontroller Pag. 97 DRV_CANFDSPI_ReadWordArray Reads an array of words (four bytes) from RAM address. Sintax int8_t DRV_CANFDSPI_ReadWordArray(CANFDSPI_MODULE_ID index, uint16_t address, uint32_t *rxd, uint16_t nWords); Parameters Index = 0 Address = Any readable/writable RAM. For example, 0x400 *rxd = Any variable. For example, iprx. nWords = number of words to read. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_ReadWordArray(0, address, iprx, 1);
Pag. 98 Report DRV_CANFDSPI_WriteWordArray Writes an array of words to RAM address. Sintax int8_t DRV_CANFDSPI_WriteWordArray(CANFDSPI_MODULE_ID index, uint16_t address, uint32_t *txd, uint16_t nWords); Parameters Index = 0 Address = Any readable/writable RAM. For example, 0x400 *rxd = Any array of words. For example ip[3] = {0x01010101,0x44444444,0x33333333} nWords = number of words to write. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_WriteWordArray(0, address, ip, 1);
CAN FD Node based on a PIC18 microcontroller Pag. 99 DRV_CANFDSPI_Configure Can control register configuration. Sintax int8_t DRV_CANFDSPI_Configure(CANFDSPI_MODULE_ID index, CAN_CONFIG* config) Parameters index = 0 config = &CAN_CONFIG. Calls the values of CAN_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple DRV_CANFDSPI_Configure(0, &config);
Pag. 100 Report DRV_CANFDSPI_ConfigureObjectReset Resets Configure Object to reset values. Sintax int8_t DRV_CANFDSPI_ConfigureObjectReset(CAN_CONFIG* config); Parameters config = &CAN_CONFIG. Calls the values of CAN_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple CAN_CONFIG config; DRV_CANFDSPI_ConfigureObjectReset(&config);
CAN FD Node based on a PIC18 microcontroller Pag. 101 DRV_CANFDSPI_OperationModeSelect Select Operation Mode. Sintax int8_t DRV_CANFDSPI_OperationModeSelect(CANFDSPI_MODULE_ID index, CAN_OPERATION_MODE opMode); Parameters index = 0 opMode = One of the following: CAN_NORMAL_MODE, CAN_SLEEP_MODE, CAN_INTERNAL_LOOPBACK_MODE, CAN_LISTEN_ONLY_MODE, CAN_CONFIGURATION_MODE, CAN_EXTERNAL_LOOPBACK_MODE, CAN_CLASSIC_MODE, CAN_RESTRICTED_MODE, CAN_INVALID_MODE. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple // Select Normal Mode DRV_CANFDSPI_OperationModeSelect(0, CAN_NORMAL_MODE);
Pag. 102 Report DRV_CANFDSPI_ModuleEventEnable Enables interrupts Sintax int8_t DRV_CANFDSPI_ModuleEventDisable(CANFDSPI_MODULE_ID index, CAN_MODULE_EVENT flags); Parameters index = 0 flags = One, or more of the following: CAN_NO_EVENT, CAN_ALL_EVENTS, CAN_TX_EVENT, CAN_RX_EVENT, CAN_TIME_BASE_COUNTER_EVENT, CAN_OPERATION_MODE_CHANGE_EVENT, CAN_TEF_EVENT, CAN_RAM_ECC_EVENT, CAN_SPI_CRC_EVENT, CAN_TX_ATTEMPTS_EVENT, CAN_RX_OVERFLOW_EVENT, CAN_SYSTEM_ERROR_EVENT, CAN_BUS_ERROR_EVENT, CAN_BUS_WAKEUP_EVENT, CAN_RX_INVALID_MESSAGE_EVENT. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_ModuleEventDisable(DRV_CANFDSPI_INDEX_0, CAN_TX_EVENT | CAN_RX_EVENT);
CAN FD Node based on a PIC18 microcontroller Pag. 103 DRV_CANFDSPI_ModuleEventDisable Disables interrupts. Sintax int8_t DRV_CANFDSPI_ModuleEventEnable(CANFDSPI_MODULE_ID index, CAN_MODULE_EVENT flags); Parameters index = 0 flags = One, or more of the following: CAN_NO_EVENT, CAN_ALL_EVENTS, CAN_TX_EVENT, CAN_RX_EVENT, CAN_TIME_BASE_COUNTER_EVENT, CAN_OPERATION_MODE_CHANGE_EVENT, CAN_TEF_EVENT, CAN_RAM_ECC_EVENT, CAN_SPI_CRC_EVENT, CAN_TX_ATTEMPTS_EVENT, CAN_RX_OVERFLOW_EVENT, CAN_SYSTEM_ERROR_EVENT, CAN_BUS_ERROR_EVENT, CAN_BUS_WAKEUP_EVENT, CAN_RX_INVALID_MESSAGE_EVENT. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_ModuleEventEnable(DRV_CANFDSPI_INDEX_0, CAN_TX_EVENT | CAN_RX_EVENT);
Pag. 104 Report DRV_CANFDSPI_GpioModeConfigure Initialize GPIO Mode. Sintax int8_t DRV_CANFDSPI_GpioModeConfigure(CANFDSPI_MODULE_ID index, GPIO_PIN_MODE gpio0, GPIO_PIN_MODE gpio1); Parameters Index = 0 gpio0 = One of the following: GPIO_MODE_INT, GPIO_MODE_GPIO gpio1 = One of the following: GPIO_MODE_INT, GPIO_MODE_GPIO Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple //Input/Output configuration DRV_CANFDSPI_GpioModeConfigure(0, GPIO_MODE_INT, GPIO_MODE_INT);
CAN FD Node based on a PIC18 microcontroller Pag. 105 DRV_CANFDSPI_ModuleEventClear Clears interrupt Flags. Sintax int8_t DRV_CANFDSPI_ModuleEventClear(CANFDSPI_MODULE_ID index, CAN_MODULE_EVENT flags); Parameters Index = 0 flags = One, or more of the following: CAN_NO_EVENT, CAN_ALL_EVENTS, CAN_TX_EVENT, CAN_RX_EVENT, CAN_TIME_BASE_COUNTER_EVENT, CAN_OPERATION_MODE_CHANGE_EVENT, CAN_TEF_EVENT, CAN_RAM_ECC_EVENT, CAN_SPI_CRC_EVENT, CAN_TX_ATTEMPTS_EVENT, CAN_RX_OVERFLOW_EVENT, CAN_SYSTEM_ERROR_EVENT, CAN_BUS_ERROR_EVENT, CAN_BUS_WAKEUP_EVENT, CAN_RX_INVALID_MESSAGE_EVENT. Return values 0 Precondition None. Side effects None. Exemple //Clear main interrupts DRV_CANFDSPI_ModuleEventClear(0, CAN_ALL_EVENTS);
Pag. 112 Report DRV_CANFDSPI_ TransmitChannelEventEnable Transmit FIFO Event Enable. Enables Transmit FIFO interrupts. Sintax int8_t DRV_CANFDSPI_TransmitChannelEventEnable(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_TX_FIFO_EVENT flags); Parameters Index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. flags = One of the following: CAN_TX_FIFO_NO_EVENT = 0, CAN_TX_FIFO_ALL_EVENTS = 0x17, CAN_TX_FIFO_NOT_FULL_EVENT = 0x01, CAN_TX_FIFO_HALF_FULL_EVENT = 0x02, CAN_TX_FIFO_EMPTY_EVENT = 0x04,CAN_TX_FIFO_ATTEMPTS_EXHAUSTED_EVENT = 0x10 Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_TransmitChannelEventEnable(0, CAN_FIFO_CHN2, CAN_TX_FIFO_NOT_FULL_EVENT);
CAN FD Node based on a PIC18 microcontroller Pag. 113 DRV_CANFDSPI_ TransmitChannelEventEnable Transmit FIFO Event Enable. Enables Transmit FIFO interrupts. Sintax int8_t DRV_CANFDSPI_TransmitChannelEventEnable(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_TX_FIFO_EVENT flags); Parameters Index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. flags = One of the following: CAN_TX_FIFO_NO_EVENT = 0, CAN_TX_FIFO_ALL_EVENTS = 0x17, CAN_TX_FIFO_NOT_FULL_EVENT = 0x01, CAN_TX_FIFO_HALF_FULL_EVENT = 0x02, CAN_TX_FIFO_EMPTY_EVENT = 0x04,CAN_TX_FIFO_ATTEMPTS_EXHAUSTED_EVENT = 0x10 Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_TransmitChannelEventEnable(0, CAN_FIFO_CHN2, CAN_TX_FIFO_NOT_FULL_EVENT);
Pag. 114 Report DRV_CANFDSPI_ TransmitChannelEventGet Transmit FIFO Event Get. Reads Transmit FIFO interrupt Flags. Sintax int8_t DRV_CANFDSPI_TransmitChannelEventGet(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_TX_FIFO_EVENT* flags); Parameters Index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. flags = &CAN_TX_FIFO_EVENT. Calls the values of CAN_TX_FIFO_EVENT previously set. Return values 0 Precondition None. Side effects None. Exemple CAN_TX_FIFO_EVENT txFlags; DRV_CANFDSPI_TransmitChannelEventGet(0, CAN_FIFO_CHN2, &txFlags);
CAN FD Node based on a PIC18 microcontroller Pag. 115 DRV_CANFDSPI_ TransmitChannelEventAttemptClear Transmit FIFO Event Clear. Clears Transmit FIFO Attempts Exhausted interrupt Flag. Sintax int8_t DRV_CANFDSPI_TransmitChannelEventAttemptClear(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel); Parameters Index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_TransmitChannelEventAttemptClear(0, CAN_FIFO_CHN2);
Pag. 116 Report DRV_CANFDSPI_ TransmitChannelConfigure Configure Transmit FIFO. Sintax int8_t DRV_CANFDSPI_TransmitChannelConfigure(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_TX_FIFO_CONFIG* config); Parameters Index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. config = &CAN_TX_FIFO_CONFIG. Calls the values of CAN_TX_FIFO_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple CAN_TX_FIFO_CONFIG txConfig; DRV_CANFDSPI_TransmitChannelConfigure(0, CAN_FIFO_CHN2, &txConfig);
CAN FD Node based on a PIC18 microcontroller Pag. 117 DRV_CANFDSPI_ TransmitChannelConfigure Configure Transmit FIFO. Sintax int8_t DRV_CANFDSPI_TransmitChannelConfigure(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_TX_FIFO_CONFIG* config); Parameters Index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. config = &CAN_TX_FIFO_CONFIG. Calls the values of CAN_TX_FIFO_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple CAN_TX_FIFO_CONFIG txConfig; DRV_CANFDSPI_TransmitChannelConfigure(0, CAN_FIFO_CHN2, &txConfig);
Pag. 118 Report DRV_CANFDSPI_ TransmitChannelConfigureObjectReset Reset TransmitChannelConfigure object to reset values. Sintax int8_t DRV_CANFDSPI_TransmitChannelConfigureObjectReset(CAN_TX_FIFO_CONFIG* config); Parameters config = &CAN_TX_FIFO_CONFIG. Calls the values of CAN_TX_FIFO_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple CAN_TX_FIFO_CONFIG txfConfig DRV_CANFDSPI_TransmitChannelConfigure(&txfConfig);
CAN FD Node based on a PIC18 microcontroller Pag. 119 DRV_CANFDSPI_ TefUpdate Transmit Event FIFO Update. Sets UINC of the TEF. Sintax int8_t DRV_CANFDSPI_TefUpdate(CANFDSPI_MODULE_ID index); Parameters index = 0 Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_TefUpdate(0);
Pag. 120 Report DRV_CANFDSPI_ TefEventGet Reads Transmit Event FIFO interrupt Flags. Sintax int8_t DRV_CANFDSPI_TefEventGet(CANFDSPI_MODULE_ID index, CAN_TEF_FIFO_EVENT* flags); Parameters index = 0 flags = &CAN_TEF_FIFO_EVENT. Calls the values of CAN_TEF_FIFO_EVENT previously set. Return values 0 Precondition None. Side effects None. Exemple CAN_TEF_FIFO_EVENT tefFlags; DRV_CANFDSPI_TefEventGet(DRV_CANFDSPI_INDEX_0, &tefFlags);
CAN FD Node based on a PIC18 microcontroller Pag. 121 DRV_CANFDSPI_ TefEventEnable Transmit Event FIFO Event Enable. Enables Transmit Event FIFO interrupts. Sintax int8_t DRV_CANFDSPI_TefEventEnable(CANFDSPI_MODULE_ID index, CAN_TEF_FIFO_EVENT flags); Parameters index = 0 flags = &CAN_TEF_FIFO_EVENT. Calls the values of CAN_TEF_FIFO_EVENT previously set. Return values 0 Precondition None. Side effects None. Exemple CAN_TEF_FIFO_EVENT tefFlags; DRV_CANFDSPI_TefEventEnable(0, &tefFlags);
Pag. 128 Report DRV_CANFDSPI_ ReceiveChannelEventGet Receive FIFO Event Get. Reads Receive FIFO interrupt Flags. Sintax int8_t DRV_CANFDSPI_ReceiveChannelEventGet(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_RX_FIFO_EVENT* flags); Parameters index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. flags = &CAN_RX_FIFO_EVENT. Calls the values of CAN_RX_FIFO_EVENT previously set. Return values 0 Precondition None. Side effects None. Exemple CAN_RX_FIFO_EVENT rxFlags; DRV_CANFDSPI_ReceiveChannelEventGet(0, CAN_FIFO_CH1, &rxFlags);
CAN FD Node based on a PIC18 microcontroller Pag. 129 DRV_CANFDSPI_ ReceiveChannelEventEnable Receive FIFO Event Enable. Enables Receive FIFO interrupts. Sintax int8_t DRV_CANFDSPI_ReceiveChannelEventEnable(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_RX_FIFO_EVENT flags); Parameters index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. flags = One, or more of the following: CAN_RX_FIFO_NO_EVENT, CAN_RX_FIFO_ALL_EVENTS, CAN_RX_FIFO_NOT_EMPTY_EVENT, CAN_RX_FIFO_HALF_FULL_EVENT, CAN_RX_FIFO_FULL_EVENT, CAN_RX_FIFO_OVERFLOW_EVENT. Return values 0 Precondition None. Side effects None. Exemple // Setup Transmit and Receive Interrupts DRV_CANFDSPI_ReceiveChannelEventEnable(0, CAN_FIFO_CH1, CAN_RX_FIFO_NOT_EMPTY_EVENT);
Pag. 130 Report DRV_CANFDSPI_ ReceiveChannelEventDisable Receive FIFO Event Disable. Disables Receive FIFO interrupts. Sintax int8_t DRV_CANFDSPI_ReceiveChannelEventDisable(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_RX_FIFO_EVENT flags); Parameters index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. flags = One, or more of the following: CAN_RX_FIFO_NO_EVENT, CAN_RX_FIFO_ALL_EVENTS, CAN_RX_FIFO_NOT_EMPTY_EVENT, CAN_RX_FIFO_HALF_FULL_EVENT, CAN_RX_FIFO_FULL_EVENT, CAN_RX_FIFO_OVERFLOW_EVENT. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_ReceiveChannelEventEnable(0, CAN_FIFO_CH1, CAN_RX_FIFO_NO_EVENT);
CAN FD Node based on a PIC18 microcontroller Pag. 131 DRV_CANFDSPI_ReceiveChannelEventOverflowClear Receive FIFO Event Clear. Clears Receive FIFO Overflow interrupt Flag. Sintax int8_t DRV_CANFDSPI_ReceiveChannelEventOverflowClear(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel); Parameters index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_ReceiveChannelEventOverflowClear(0, CAN_FIFO_CH1);
Pag. 132 Report DRV_CANFDSPI_ ReceiveChannelConfigureObjectReset Reset ReceiveChannelConfigure object to reset value. Sintax int8_t DRV_CANFDSPI_ReceiveChannelConfigureObjectReset(CAN_RX_FIFO_CONFIG* config); Parameters config = & CAN_RX_FIFO_CONFIG. Calls the values of CAN_RX_FIFO_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple // Setup RX FIFO CAN_RX_FIFO_CONFIG rxConfig DRV_CANFDSPI_ReceiveChannelConfigureObjectReset(&rxConfig);
CAN FD Node based on a PIC18 microcontroller Pag. 133 DRV_CANFDSPI_ ReceiveChannelConfigure Configure Receive FIFO. Sintax int8_t DRV_CANFDSPI_ReceiveChannelConfigure(CANFDSPI_MODULE_ID index, CAN_FIFO_CHANNEL channel, CAN_RX_FIFO_CONFIG* config); Parameters index = 0 channel = CAN_FIFO_CHN. Being N any number between 0 and 31. config = & CAN_RX_FIFO_CONFIG. Calls the values of CAN_RX_FIFO_CONFIG previously set. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple // Setup RX FIFO CAN_RX_FIFO_CONFIG rxConfig DRV_CANFDSPI_ReceiveChannelConfigure(0, CAN_FIFO_CH1, &rxConfig);
Pag. 134 Report DRV_CANFDSPI_BitTime Configure Bit Time registers (based on CAN clock speed). Sintax int8_t DRV_CANFDSPI_BitTimeConfigure(CANFDSPI_MODULE_ID index, CAN_BITTIME_SETUP bitTime, CAN_SSP_MODE sspMode, CAN_SYSCLK_SPEED clk); Parameters index = 0 bitTime = selectedBitTime. For example, CAN_500K_2M sspMode = One of the following: CAN_SSP_MODE_OFF, CAN_SSP_MODE_MANUAL, CAN_SSP_MODE_AUTO. clk = CAN_SYSCLK_40M or CAN_SYSCLK_20M Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple // Setup Bit Time DRV_CANFDSPI_BitTimeConfigure(DRV_CANFDSPI_INDEX_0, selectedBitTime, CAN_SSP_MODE_AUTO, CAN_SYSCLK_40M);
CAN FD Node based on a PIC18 microcontroller Pag. 135 DRV_CANFDSPI_BitTimeConfigureData10Mhz Configure Bit Time registers (based on CAN clock speed). Sintax int8_t DRV_CANFDSPI_BitTimeConfigureData10MHz(CANFDSPI_MODULE_ID index, CAN_BITTIME_SETUP bitTime, CAN_SSP_MODE sspMode) Parameters index = 0 bitTime = selectedBitTime. For example, CAN_500K_2M sspMode = One of the following: CAN_SSP_MODE_OFF, CAN_SSP_MODE_MANUAL, CAN_SSP_MODE_AUTO. Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple // Setup Bit Time DRV_CANFDSPI_BitTimeConfigureData10MHz(0, selectedBitTime, CAN_SSP_MODE_AUTO);
Pag. 136 Report DRV_CANFDSPI_BitTimeConfigureNominal20Mhz Configure Bit Time registers (based on CAN clock speed). Sintax int8_t DRV_CANFDSPI_BitTimeConfigureNominal20MHz(CANFDSPI_MODULE_ID index, CAN_BITTIME_SETUP bitTime) Parameters index = 0 bitTime = selectedBitTime. For example, CAN_500K_2M Return values 0 Precondition Must be in configuration mode. Side effects None. Exemple // Setup Bit Time DRV_CANFDSPI_BitTimeConfigureNominal20MHz(0, selectedBitTime);
CAN FD Node based on a PIC18 microcontroller Pag. 137 DRV_CANFDSPI_EccEnable Enable ECC. Sintax int8_t DRV_CANFDSPI_EccEnable(CANFDSPI_MODULE_ID index); Parameters index = 0 Return values 0 Precondition None. Side effects None. Exemple DRV_CANFDSPI_EccEnable(0);
Pag. 144 Report DRV_CANFDSPI_FilterMaskConfigure Filter Mask Configuration. Configures Mask of filter object. Sintax int8_t DRV_CANFDSPI_FilterMaskConfigure(CANFDSPI_MODULE_ID index, CAN_FILTER filter, CAN_MASKOBJ_ID* mask); Parameters Index = 0 filter = CAN_FILTERN, being N any number between 0 and 31. It usually works with N = 0. mask = calls the values of the CAN_MASKOBJ_ID, previously set. Return values 0 Precondition Must be in configuration mode. The filter must be disabled before changing the mask object. Side effects None. Exemple mObj.bF.MSIDA = 0x0; mObj.bF.MSIDB = 0x0; mObj.bF.MIDE = 1; // Only allow standard IDs mObj.bF.MEIDA = 0x0; mObj.bF.MEIDB = 0x0; DRV_CANFDSPI_FilterMaskConfigure(0, CAN_FILTER0, &mObj.bF);
CAN FD Node based on a PIC18 microcontroller Pag. 145 DRV_CANFDSPI_FilterToFifoLink Link Filter to FIFO. Initializes the Pointer from Filter to FIFO. Enables or disables the Filter Sintax int8_t DRV_CANFDSPI_FilterToFifoLink(CANFDSPI_MODULE_ID index, CAN_FILTER filter, CAN_FIFO_CHANNEL channel, bool enable); Parameters Index = 0 filter = CAN_FILTERN, being N any number between 0 and 31. It usually works with N = 0. channel = CAN_CHANNEL, being N any number between 0 and 31. The RX channel is CAN_FIFO_CH1, whether the TX channel is CAN_FIFO_CH2. bool = true or false. True, enables the filter, while False disables the filter. Return values 0 Precondition None. Side effects None. Exemple // Link FIFO and Filter DRV_CANFDSPI_FilterToFifoLink(0, CAN_FILTER0, APP_RX_FIFO, true);
Pag. 146 Report DRV_CANFDSPI_TefConfigure Link Filter to FIFO. Initializes the Pointer from Filter to FIFO. Enables or disables the Filter Sintax int8_t DRV_CANFDSPI_FilterToFifoLink(CANFDSPI_MODULE_ID index, CAN_FILTER filter, CAN_FIFO_CHANNEL channel, bool enable); Parameters Index = 0 filter = CAN_FILTERN, being N any number between 0 and 31. It usually works with N = 0. channel = CAN_CHANNEL, being N any number between 0 and 31. The RX channel is CAN_FIFO_CH1, whether the TX channel is CAN_FIFO_CH2. bool = true or false. True, enables the filter, while False disables the filter. Return values 0 Precondition None. Side effects None. Exemple // Link FIFO and Filter DRV_CANFDSPI_FilterToFifoLink(0, CAN_FILTER0, APP_RX_FIFO, true);