Download Kinetis Quick Reference User Guide
Transcript
Configuration examples
pFlexCANReg->MB[iTxMBNo].WORD1 = word[1];
// Start transmit with specified tx code
pFlexCANReg->MB[iTxMBNo].CS = (pFlexCANReg->MB[iTxMBNo].CS
& ~(FLEXCAN_MB_CS_CODE_MASK))
| FLEXCAN_MB_CS_CODE(txCode) // write activate code
| FLEXCAN_MB_CS_LENGTH(iNoBytes);
15.2.4 Read message
Before reading the message content, it is necessary to lock the Rx MB. After reading the
message content, unlock the Rx MB. Polling or interrupt method can be used to check an
Rx MB to see whether it has received a message.
15.2.4.1 Code example and explanation
Here is a code example for checking the IFLAG1[MB] and reading the message from the
Rx MB:
if(pFlexCANReg->IFLAG1 & (1<<iMB))
{
// Read the Message content information
// clear flag
pFlexCANReg->IFLAG1 = (1<<iMB);
}
This code is used to read the message content:
// Lock the MB
code = FLEXCAN_get_code(pFlexCANReg->MB[iMB].CS);
length = FLEXCAN_get_length(pFlexCANReg->MB[iMB].CS);
//
format = (pFlexCANReg->MB[iMB].CS & FLEXCAN_MB_CS_IDE)? 1:0;
*id = (pFlexCANReg->MB[iMB].ID & FLEXCAN_MB_ID_EXT_MASK);
if(!format)
{
// standard ID
*id >>= FLEXCAN_MB_ID_STD_BIT_NO;
}
else
{
*id |= CAN_MSG_IDE_MASK;
// flag extended ID
}
format = (pFlexCANReg->MB[iMB].CS & FLEXCAN_MB_CS_RTR)? 1:0;
if(format)
{
*id |= CAN_MSG_TYPE_MASK;
// flag Remote Frame type
}
// Read message bytes
wno = (length-1)>>2;
bno = length-1;
if(wno>0)
{
//
(*(uint32*)pBytes) = pFlexCANReg->MB[iMB].WORD0;
swap_4bytes(pBytes);
bno -= 4;
pMBData = (uint8*)&pFlexCANReg->MB[iMB].WORD1+3;
}
Kinetis Quick Reference User Guide, Rev. 0, 11/2010
146
Freescale Semiconductor