How to receive multiple IDs in a single buffer on flexcan

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to receive multiple IDs in a single buffer on flexcan

223 次查看
Oido
Contributor I

 I'm using S32K144W and I can only use up to 7 buffers with CAN FD and 64byte, but I have a lot of CAN IDs to use.
Is it possible to use multiple IDs with one buffer?
For example, CAN0->RAMn [1*MSG_BUF_SIZE + 0] = 0xC4000000;
CAN0->RAMn[ 1*MSG_BUF_SIZE + 1] = 0x100<<18;
With buffer one.
And when I receive data of various different IDs using buffer 1, should I initialize the buffer every time I receive it?

It's part of the code, but as buffer 1, I use buffer 0x100, buffer 2
You can receive up to 0x200-20F.

 uint32_t  RxCODE;             
 uint32_t  RxID;               
 uint32_t  RxLENGTH;            
 uint32_t  RxDATA[16]={0,};          
 uint32_t  RxDATA2[16]={0,};          
 uint32_t  RxDATA3[16]={0,};           
 uint32_t  RxTIMESTAMP;
 
void CAN0_Init(void)
{
#define MSG_BUF_SIZE  18 
uint32_t   i=0;
uint32_t   k=0;
PCC->PCCn[PCC_FlexCAN0_INDEX] |= PCC_PCCn_CGC_MASK; 
CAN0->MCR |= CAN_MCR_MDIS_MASK; 
CAN0->CTRL1 |= CAN_CTRL1_CLKSRC_MASK; 
CAN0->MCR &= ~CAN_MCR_MDIS_MASK; //CAN 
while (!((CAN0->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT))  {} 
 
for(i=0; i<7; i++ ) 
{
for(k=0;k<16;k++)
{
CAN0->RAMn[i*MSG_BUF_SIZE +2+k] = 0;
}
}
 
CAN0->RXMGMASK = 0x1FFFFFFF;  
 
CAN0->RAMn[ 1*MSG_BUF_SIZE + 0] = 0xC4000000;
CAN0->RAMn[ 1*MSG_BUF_SIZE + 1] = 0x100<<18;
 
CAN0->RAMn[ 3*MSG_BUF_SIZE + 0] = 0xC4000000; 
CAN0->RAMn[ 3*MSG_BUF_SIZE + 1] = 0x200<<18;
CAN0->RXIMR[3] = 0x3F0<<18; 
 
CAN0->FDCTRL = CAN_FDCTRL_FDRATE_MASK|CAN_FDCTRL_MBDSR0(3)|CAN_FDCTRL_TDCEN_MASK|CAN_FDCTRL_TDCOFF(5);
 
CAN0->CTRL2 = CAN_CTRL2_ISOCANFDEN_MASK; //ISO CANFD 온
CAN0->MCR =CAN_MCR_IRMQ_MASK|CAN_MCR_MAXMB(6)|CAN_MCR_FDEN_MASK;//CAN_MCR_IRMQ_MASK|
 
while ((CAN0->MCR && CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT)  {}
 
while ((CAN0->MCR && CAN_MCR_NOTRDY_MASK) >> CAN_MCR_NOTRDY_SHIFT)  {}
}
 
 
void CAN0RX(void)
{
uint8_t j;
 
RxCODE   = (CAN0->RAMn[ 3*MSG_BUF_SIZE + 0] & 0x07000000) >> 24;  //CODE 7
RxID     = (CAN0->RAMn[ 3*MSG_BUF_SIZE + 1] & CAN_WMBn_ID_ID_MASK)  >> CAN_WMBn_ID_ID_SHIFT ;
RxLENGTH = (CAN0->RAMn[ 3*MSG_BUF_SIZE + 0] & CAN_WMBn_CS_DLC_MASK) >> CAN_WMBn_CS_DLC_SHIFT;
 
for(j=0; j<16; j++ ) 
{
RxDATA[j]=CAN0->RAMn[1*MSG_BUF_SIZE +2+j];
RxDATA3[j]=CAN0->RAMn[3*MSG_BUF_SIZE +2+j];
}
 
CAN0->IFLAG1 = 0x00000010;
}
0 项奖励
回复
0 回复数