Classical CAN test of LPC55S16

Publisher:breakthrough3Latest update time:2024-08-19 Source: cnblogsKeywords:CAN  Test Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I got the LPC55S16 board several days ago. The original goal was to test the CANFD and USB conversion communication. I found that there are quite a lot of peripherals connected to the board, so I can play with it for a while. Before testing CANFD communication, test Classical CAN first. The difference between the two is described in detail on the Internet. The main difference is the communication rate. The data bit rate is increased to 8Mbps and the maximum data frame is increased to 64 bytes. Currently, it is only considered at the application level. The official SDK provides MCAN routines. Considering that NXP's IDE is still being familiarized, it is more convenient to port it to Keil for debugging, as shown in Figure 1.

The purpose of this test is to complete the Classical CAN to send 8 bytes every 2 seconds and interrupt the reception.

The connection diagram is shown in Figure 2:

The official schematic diagram is shown in Figure 3:

After porting the demo to Keil, it is time to read the program and then modify the program for the purpose of testing.

The 2S delay uses SYSTick, as follows:

  1. /* Set systick reload value to generate 1ms interrupt */

  2. if (SysTick_Config(SystemCoreClock / 1000U))

  3. {

  4. while (1)

  5. {

  6. }

  7. }

  8. SysTick_DelayTicks(2000U);


According to the previous definition, initialize the clock, pin, CAN definition, mainly the number of bytes, ID and baud rate.

The idea of ​​the whole process is to test CAN sending first, if there is no problem, then test CAN receiving, and finally integrate it.

Baud rate usage:

  1. if (MCAN_CalculateImprovedTimingValues(mcanConfig.baudRateA, MCAN_CLK_FREQ, &timing_config))

  2. {

  3. /* Update the improved timing configuration*/

  4. memcpy(&(mcanConfig.timingConfig), &timing_config, sizeof(mcan_timing_config_t));

  5. }


You can trace back to the definition of baud rate. The demo uses baudRateA 500Kbps, but you can also choose 1Mbps.

Send configuration:

  1. /* TX buffer config. */

  2. memset(&txBuffer, 0, sizeof(txBuffer));

  3. txBuffer.address = TX_BUFFER_OFS;

  4. txBuffer.dedicatedSize = 1U;

  5. txBuffer.fqSize = 0;

  6. txBuffer.datafieldSize = kMCAN_8ByteDatafield;

  7. MCAN_SetTxBufferConfig(EXAMPLE_MCAN, &txBuffer);


Mode selection:

  1. /* Finish software initialization and enter normal mode, synchronizes to

  2. CAN bus, ready for communication */

  3. MCAN_EnterNormalMode(EXAMPLE_MCAN);


Receive configuration:

  1. /* STD filter config. */

  2. rxFilter.address = STD_FILTER_OFS;

  3. rxFilter.idFormat = kMCAN_FrameIDStandard;

  4. rxFilter.listSize = 1U;

  5. rxFilter.nmFrame = kMCAN_reject0;

  6. rxFilter.remFrame = kMCAN_rejectFrame;

  7. MCAN_SetFilterConfig(EXAMPLE_MCAN, &rxFilter);


  8. stdFilter.sfec = kMCAN_storeinFifo0;

  9. /* Classic filter mode, only filter matching ID. */

  10. stdFilter.sft = kMCAN_classic;

  11. stdFilter.sfid1 = rxIdentifier;

  12. stdFilter.sfid2 = 0x7FFU;

  13. MCAN_SetSTDFilterElement(EXAMPLE_MCAN, &rxFilter, &stdFilter, 0);


  14. /* RX fifo0 config. */

  15. rxFifo0.address = RX_FIFO0_OFS;

  16. rxFifo0.elementSize = 1U;

  17. rxFifo0.watermark = 0;

  18. rxFifo0.opmode = kMCAN_FifoBlocking;

  19. rxFifo0.datafieldSize = kMCAN_8ByteDatafield;


Send the frame format and complete the sending:

  1. txIdentifier = 0x123U;

  2. txFrame.xtd = kMCAN_FrameIDStandard;

  3. txFrame.rtr = kMCAN_FrameTypeData;

  4. txFrame.fdf = 0;

  5. txFrame.brs = 0;

  6. txFrame.dlc = 8U;

  7. txFrame.id = txIdentifier << STDID_OFFSET;

  8. txFrame.data = tx_datac;

  9. txFrame.size = CAN_DATASIZE;

  10. txXfer.frame = &txFrame;

  11. txXfer.bufferIdx = 0;

  12. MCAN_TransferSendNonBlocking(EXAMPLE_MCAN, &mcanHandle, &txXfer);


Receive frame format and complete data reception:

  1. rxIdentifier = 0x321U;


During the test, there is a paragraph in the demo:

  1. while (!rxComplete)

  2. {

  3. }

  4. rxComplete = false;


Just use a while statement, and the message will be sent only after it is received. If it is blocked, it will not affect the sending on time.

The sending and receiving data are shown in Figure 4 and Figure 5:

The document "How to Use CAN-FD to Transfer Data on LPC5500 Series" also explains the Timing config, which needs to be further understood in in-depth study. After testing CAN, we will continue with CANFD.

By the way, I have to complain that many official documents are not available on the Internet and need to be found, which will take some extra time.


Keywords:CAN  Test Reference address:Classical CAN test of LPC55S16

Previous article:LPC553X MCU Architecture Overview
Next article:Madplay configuration of ok6410

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号