第 33 页 共 60 页
3. CAN frame to SPI frame conversion( CAN
→
SPI )
TD5(3)USPCAN, as an SPI slave, can't actively control SPI peripherals. When the product receives a frame
of data from the CAN bus, it can only be stored in the CAN receiving buffer immediately. When the number
of CAN frames in the CAN buffer reaches the feedback trigger frame number or trigger time, the INT pin
outputs a low level to inform the SPI master to read data.
After the SPI master acquires the size of the CAN buffer from TD5(3)USPCAN, SPI CAN read out all the
CAN frame data contained in the CAN buffer by one frame.
In SPI-to-CAN mode, it is considered that one SPI frame data is a collection of multiple CAN frame data
most of the time. In order to effectively distinguish CAN frame ID from data, CAN receiving buffer is a
collection of frame information, frame ID and frame data. In the transparent conversion with identification
mode, the CAN receiving buffer is a collection of frame information, frame ID and frame data. When the
CAN terminal receives a CAN data frame, the product simultaneously places the frame information, frame ID
and frame data into the buffer. CAN frame information is stored as the first byte, and the frame ID is stored at
the specified location according to the user-configured starting address and length. Frame information,
frame ID bytes and frame data bytes form a "byte segment", and each byte segment includes the frame
information, frame ID and data of an independent CAN frame, in which the high bit of the frame ID comes
first.
The information is represented by one byte, in which 7~4 bits refer to the frame type, 0000 represents the
standard frame and 1000 represents the extended frame. 3~0 bits represent "data length", and "0000~1000"
respectively represent "0~8" bits of data.
For example, the frame information is 0x05, which means that the CAN frame type is a standard frame,
and the data length of the CAN frame is 5 bytes. The frame information is 0x86, which means that the CAN
frame type is extended frame, and the data length of CAN frame is 6 bytes.
After acquiring the size of the CAN receiving buffer, the master can read out the N byte segments stored
in the buffer by one SPI frame at a time. Its conversion data format is as follows.