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:
-
/* Set systick reload value to generate 1ms interrupt */
-
if (SysTick_Config(SystemCoreClock / 1000U))
-
{
-
while (1)
-
{
-
}
-
}
-
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:
-
if (MCAN_CalculateImprovedTimingValues(mcanConfig.baudRateA, MCAN_CLK_FREQ, &timing_config))
-
{
-
/* Update the improved timing configuration*/
-
memcpy(&(mcanConfig.timingConfig), &timing_config, sizeof(mcan_timing_config_t));
-
}
You can trace back to the definition of baud rate. The demo uses baudRateA 500Kbps, but you can also choose 1Mbps.
Send configuration:
-
/* TX buffer config. */
-
memset(&txBuffer, 0, sizeof(txBuffer));
-
txBuffer.address = TX_BUFFER_OFS;
-
txBuffer.dedicatedSize = 1U;
-
txBuffer.fqSize = 0;
-
txBuffer.datafieldSize = kMCAN_8ByteDatafield;
-
MCAN_SetTxBufferConfig(EXAMPLE_MCAN, &txBuffer);
Mode selection:
-
/* Finish software initialization and enter normal mode, synchronizes to
-
CAN bus, ready for communication */
-
MCAN_EnterNormalMode(EXAMPLE_MCAN);
Receive configuration:
-
/* STD filter config. */
-
rxFilter.address = STD_FILTER_OFS;
-
rxFilter.idFormat = kMCAN_FrameIDStandard;
-
rxFilter.listSize = 1U;
-
rxFilter.nmFrame = kMCAN_reject0;
-
rxFilter.remFrame = kMCAN_rejectFrame;
-
MCAN_SetFilterConfig(EXAMPLE_MCAN, &rxFilter);
-
-
stdFilter.sfec = kMCAN_storeinFifo0;
-
/* Classic filter mode, only filter matching ID. */
-
stdFilter.sft = kMCAN_classic;
-
stdFilter.sfid1 = rxIdentifier;
-
stdFilter.sfid2 = 0x7FFU;
-
MCAN_SetSTDFilterElement(EXAMPLE_MCAN, &rxFilter, &stdFilter, 0);
-
-
/* RX fifo0 config. */
-
rxFifo0.address = RX_FIFO0_OFS;
-
rxFifo0.elementSize = 1U;
-
rxFifo0.watermark = 0;
-
rxFifo0.opmode = kMCAN_FifoBlocking;
-
rxFifo0.datafieldSize = kMCAN_8ByteDatafield;
Send the frame format and complete the sending:
-
txIdentifier = 0x123U;
-
txFrame.xtd = kMCAN_FrameIDStandard;
-
txFrame.rtr = kMCAN_FrameTypeData;
-
txFrame.fdf = 0;
-
txFrame.brs = 0;
-
txFrame.dlc = 8U;
-
txFrame.id = txIdentifier << STDID_OFFSET;
-
txFrame.data = tx_datac;
-
txFrame.size = CAN_DATASIZE;
-
txXfer.frame = &txFrame;
-
txXfer.bufferIdx = 0;
-
MCAN_TransferSendNonBlocking(EXAMPLE_MCAN, &mcanHandle, &txXfer);
Receive frame format and complete data reception:
-
rxIdentifier = 0x321U;
During the test, there is a paragraph in the demo:
-
while (!rxComplete)
-
{
-
}
-
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.
Previous article:LPC553X MCU Architecture Overview
Next article:Madplay configuration of ok6410
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Proteus emulation of micropython method
- What is the principle of the reading pen? How does it improve the accuracy of reading?
- Where is the lucky star? ——"Keysight Technology Double 11 Instrument Flash Sale"
- My design is equivalent to changing the original manual control to automatic control. The overall design idea is as follows, but at this stage it is still...
- Play with the Internet of Things and make a smart greenhouse model!
- I used the AD18STM32 library to import the chip, but the chip pins are incomplete
- MSP430 interrupt nesting mechanism
- Current sensing crosstalk issue?
- Electronic pill box reminder solution
- The first analog I2C program learned by MSP430