CAN-FD 64 bytes on MCP5748G

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

CAN-FD 64 bytes on MCP5748G

ソリューションへジャンプ
408件の閲覧回数
Kazarian
Contributor II

Hello, 

This is a continuation of this thread , the TX/RX for CAN-FD frame of 8 bytes works fine, i want to configure the module tu support 64bytes. the changes made so far are : 

FDCTR

Kazarian_0-1710402914481.png

Increase message buffer to support 64 bytes

Kazarian_1-1710402999175.png

MB0 and MB1 seems to have the correctly lenght in the register view :

Kazarian_2-1710403273162.png

No interrupppt is triggered once i send a CAN frame from canoe. i think other configuration could be needed , below is the code for the config :

ErrorCode FlexCANDevice::init()
{
        /* enable the FlexCAN module, reset and freeze */
		fpDevice->MCR.R = (0
						| CAN_MCR_FRZ  /* enabled to enter Freeze mode */ 
						| CAN_MCR_HALT /* enter freeze mode if FRZ bit is set */
						//| CAN_MCR_SOFTRST /* soft reset */
						//| CAN_MCR_SRXDIS  /* self reception enable */
						| CAN_MCR_BCC  /* individual Rx masking and queue */
						| 0x0000003F);                      
		
		/* double check that we are actually in freeze mode */
		while(0 == fpDevice->MCR.B.FRZACK) {};
		while(0 == fpDevice->MCR.B.NOTRDY) {};
		
		fpDevice->MCR.R = (0
						| CAN_MCR_FRZ  /* enabled to enter Freeze mode */ 
						| CAN_MCR_HALT /* enter freeze mode if FRZ bit is set */                    
						| CAN_MCR_SRXDIS  /* self reception disabled */
						| CAN_MCR_BCC  /* individual Rx masking and queue */
						| CAN_MCR_AEN  /* Safe Tx abort enable */
						| CAN_MCR_FDEN /* CAN FD enabled */
						| 0x0000003F); /* enable 64 MBs */  

		// Set CAN Bit Timing Register (CAN_CBT. P-1747)
		fpDevice->CBT.B.BTF 	 = 1; 		// Enable extended bit time definitions
		fpDevice->CBT.B.EPRESDIV =	fConfig.bitrate_cbt.presDiv;
		fpDevice->CBT.B.ERJW 	 =  fConfig.bitrate_cbt.rjw;  
		fpDevice->CBT.B.EPROPSEG =  fConfig.bitrate_cbt.propSeg;	 
		fpDevice->CBT.B.EPSEG1   =  fConfig.bitrate_cbt.pSeg1;  
		fpDevice->CBT.B.EPSEG2   =  fConfig.bitrate_cbt.pSeg2; 

		// Set CAN FD Bit Timing register (CAN_FDCBT. P-1768)
		fpDevice->FDCBT.B.FPRESDIV = fConfig.bitrate.presDiv;
		fpDevice->FDCBT.B.FRJW     = fConfig.bitrate.rjw;
		fpDevice->FDCBT.B.FPROPSEG = fConfig.bitrate.propSeg;
		fpDevice->FDCBT.B.FPSEG1   = fConfig.bitrate.pSeg1;
		fpDevice->FDCBT.B.FPSEG2   = fConfig.bitrate.pSeg2;
		
		// Set CAN FD Control register (CAN_FDCTRL .P-1766)
		fpDevice->FDCTRL.R = 0;
		fpDevice->FDCTRL.B.FDRATE = 1;   			  // bit rate switching enable
		fpDevice->FDCTRL.B.TDCEN = 0;
		//fpDevice->FDCTRL.B.TDCOFF = 32;
		fpDevice->FDCTRL.B.MBDSR0 = fConfig.payload;

		// Enable CAN ISO
		fpDevice->CTRL2.B.ISOCANFDEN = 1;

		// Setup message buffers
		fRxInterruptMask = 0;
		uint32_t mask = 1;

		// Setup MB0 for sending
		setupMessageBuffer(0, CANTxBuffer::CODE_INACTIVE, false);

		// Setup MB1 for receiving
		setupMessageBuffer(1, CANRxBuffer::CODE_EMPTY, false);
		fRxInterruptMask |= mask;

		mask <<= 1;
	


	return CAN_ERR_OK;
}

void setupMessageBuffer(uint8_t bufIdx, uint8_t code, bool extended)
{
	fpDevice->MB[bufIdx].CS.R = 0;
	fpDevice->MB[bufIdx].CS.B.IDE = extended ? 1 : 0;
	fpDevice->MB[bufIdx].CS.B.CODE = code;
	fpDevice->MB[bufIdx].ID.R = 0;
	for (int i = 0; i < 16; i++) {
		fpDevice->MB[bufIdx].DATA.W[i] = 0;
	}
	fpDevice->RXIMR[bufIdx].R = 0;
}

 

Thank you.

Best regards.

 

0 件の賞賛
1 解決策
370件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, you have to, if want to use this structure.
You shared below

PetrS_0-1710485027465.png

debugger shows MBs in right manner for 64byte payload but your init is wrong. Empty CODE for RX MB is on wrong offset.

BR, Petr 

元の投稿で解決策を見る

7 返答(返信)
399件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

be sure you are using right offset for MBs for higher payload setting. From the last picture it is evident you have still offset for 8byte payload setting. See chapter 73.6.5 FlexCAN message buffer memory map for more info 

PetrS_0-1710414921649.png

BR, Petr

0 件の賞賛
393件の閲覧回数
Kazarian
Contributor II

Hi @PetrS 

Thanks for the hint. offset is corrected now 

Kazarian_0-1710416509529.png

but i could not receive interrupt when sending FD fram with 64byte payload , it works only with 8 bytes?

this is the register view :

Kazarian_1-1710416588417.pngKazarian_2-1710416644319.png

Thank you.

0 件の賞賛
390件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

show repaired MB area, and specify what is send from CAN tool. Do you see any error detected there?

BR, Petr

0 件の賞賛
380件の閲覧回数
Kazarian
Contributor II

Hello @PetrS 

No the tool does not report any error, the data inside the frame is :

Kazarian_0-1710451504106.png

 

shouldn't we modify also the message buffer initialisation since we use 32-64 bytes ? 

Kazarian_1-1710451781706.png

Best regards.

0 件の賞賛
371件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, you have to, if want to use this structure.
You shared below

PetrS_0-1710485027465.png

debugger shows MBs in right manner for 64byte payload but your init is wrong. Empty CODE for RX MB is on wrong offset.

BR, Petr 

358件の閲覧回数
Kazarian
Contributor II

Hello @PetrS ,

Yes you are right, the address Offfset for the MB is wrong.

i could not find/oversee in datasheet where i can set the address offset for each MB ? i could only set the 

MBDSR on FDCTRL register. can you please point where to set the correct offset ?
 
Thank you.
0 件の賞賛
356件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I already mentioned it in previous reply.

BR, Petr

0 件の賞賛