AnsweredAssumed Answered

S32K144  CAN1 can't receive data  

Question asked by shenlan zeng on Aug 21, 2017

Hi,

I have a promble about s32k144's flexcan,it is the can's receiving,it's send is ok,but can't receive data,the code like that:
void PORT_Init_Can (void)
{
PCC->PCCn[PCC_PORTE_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clock for PORTE */
PORTE->PCR[4] |= PORT_PCR_MUX(5); /* Port E4: MUX = ALT5, CAN0_RX */
PORTE->PCR[5] |= PORT_PCR_MUX(5); /* Port E5: MUX = ALT5, CAN0_TX */
}
void FLEXCANx_init(CAN_Type *CANx,uint32_t baud)
{
#define MSG_BUF_SIZE 4
uint32_t i=0;
if(CANx == CAN0)
{
PCC->PCCn[PCC_FlexCAN0_INDEX] |= PCC_PCCn_CGC_MASK;
}
else
{
PCC->PCCn[PCC_FlexCAN1_INDEX] |= PCC_PCCn_CGC_MASK;
}
CANx->MCR |= CAN_MCR_MDIS_MASK;
CANx->CTRL1 &= ~CAN_CTRL1_CLKSRC_MASK;
CANx->MCR &= ~CAN_MCR_MDIS_MASK;
while (!((CANx->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT)) {}
if(baud == 250)
{
CANx->CTRL1 = 0x01DB0006;
}
else if(baud == 500)
{
CANx->CTRL1 = 0x00DB0006;
}
for(i=0; i<128; i++ )
{
CANx->RAMn[i] = 0;
}
for(i=0; i<16; i++ )
{
CANx->RXIMR[i] = 0xFFFFFFFF;
}
CANx->RXMGMASK = 0x1FFFFFFF;
CANx->RAMn[ 4*MSG_BUF_SIZE + 0] = 0x04100000;
CANx->RAMn[ 4*MSG_BUF_SIZE + 1] = 0x18ff50e5;
CANx->MCR = 0x0000001F;
while ((CANx->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT) {}
while ((CANx->MCR & CAN_MCR_NOTRDY_MASK) >> CAN_MCR_NOTRDY_SHIFT) {}
}
void init_IRQs (void)
{
NVIC->ICPR[1] = 1 << (82 % 32);
NVIC->ISER[1] = 1 << (82 % 32);
NVIC->IP[82] = 0xA;
}
void Can_Send(uint32_t id,uint8_t *data,uint8_t len)
{
CAN0->IFLAG1 = 0x00000001;
CAN0->RAMn[ 0*MSG_BUF_SIZE + 2] = (data[3]|data[2]<<8|data[1]<<16|data[0]<<24);
CAN0->RAMn[ 0*MSG_BUF_SIZE + 3] = (data[7]|data[6]<<8|data[5]<<16|data[4]<<24);
CAN0->RAMn[ 0*MSG_BUF_SIZE + 1] = id;
CAN0->RAMn[ 0*MSG_BUF_SIZE + 0] = 0x0C600000 | 8 <<CAN_WMBn_CS_DLC_SHIFT;
}
void FLEXCAN0_receive_msg(void)
{
uint8_t j;
uint32_t dummy;
RxCODE = (CAN0->RAMn[ 4*MSG_BUF_SIZE + 0] & 0x07000000) >> 24;
RxID = (CAN0->RAMn[ 4*MSG_BUF_SIZE + 1] & CAN_WMBn_ID_ID_MASK) >> CAN_WMBn_ID_ID_SHIFT ;
RxLENGTH = (CAN0->RAMn[ 4*MSG_BUF_SIZE + 0] & CAN_WMBn_CS_DLC_MASK) >> CAN_WMBn_CS_DLC_SHIFT;
for (j=0; j<2; j++)
{
RxDATA[j] = CAN0->RAMn[ 4*MSG_BUF_SIZE + 2 + j];
}
RxTIMESTAMP = (CAN0->RAMn[ 0*MSG_BUF_SIZE + 0] & 0x000FFFF);
dummy = CAN0->TIMER;
CAN0->IFLAG1 = 0x00000010;
}
I call the function like that :
uint8_t can_test[8]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
Can_Send(0x1806e5f4,&can_test[0],8);
FLEXCAN0_receive_msg();
the results like that:
can you help me solve the promble,thanks for your help! i don‘t know if it is the mailbox is not activated。
the EVB like that:

Outcomes