Dear Kef,
Thanks help me.
In bootloader ,address belong to 0xF000-0xFFF,can initialization code is here:
void bootloader_InitCAN0(void){
CAN0CTL0 = 0x01; // MSCAN in initialization mode
while (!(CAN0CTL1_INITAK)); // Wait for initialization mode acknowledge
CAN0CTL1_CANE = 1; // Enable MSCAN module
CAN0CTL1_LISTEN = 0; // Not listen only mode
CAN0CTL1_WUPM = 1;
CAN0CTL1_BORM = 1;
......
CAN0IDAR0 = 0xFD;//(byte)(BOOT_RX_ID>>3);
CAN0IDAR1 = 0x60;//(byte)((BOOT_RX_ID<<5)&0xE0); // only down loader id is accepted
CAN0IDAR2 = 0xFF;
CAN0IDAR3 = 0xFF;
CAN0IDMR4 = 0x00;
CAN0IDMR5 = 0x1F;
CAN0IDMR6 = 0xFF;
CAN0IDMR7 = 0xFF;
CAN0IDAR4 = 0xFD;//(byte)(BOOT_RX_ID>>3);
CAN0IDAR5 = 0x60;//(byte)((BOOT_RX_ID<<5)&0xE0); // only down loader id is accepted
CAN0IDAR6 = 0xFF;
CAN0IDAR7 = 0xFF;
CAN0CTL0 = 0x00; // Exit initialization mode request
while (CAN0CTL1_INITAK); // Wait for normal mode
CAN0CTL0 = 0x00; // Exit initialization mode request
CAN0RIER = 0x01; // Enable Receive interrupt
CAN0TIER = 0x00; //disable send interrupt flag
while(!(CAN0CTL0_SYNCH)); // Wait for CAN synchronization
RxMsg.DtLen = 0;
}
My application code CAN initialization is here,since it has some other feature and I can not use bootloader_InitCAN0 from bootloader.
void InitCAN(u8 channelNo,u8 baudrate)
{
u32 _id;
volatile MSCANReg *stCanMsgReg;
volatile XGCANstruct *stXGCANStruct;
//stXGCANStruct = (volatile XGCANstruct *)(&ChannelCAN0);
#ifdef USE_CAN0
if(channelNo == 0)
{
stXGCANStruct = (volatile XGCANstruct *)(&ChannelCAN0);
}
#endif
if(channelNo == 4)
{
stXGCANStruct = (volatile XGCANstruct *)(&ChannelCAN4);
}
stCanMsgReg = (volatile MSCANReg *)stXGCANStruct->pCAN; //get CAN register
(stCanMsgReg->can_ctl0).Byte= 1;//MSCAN in initialization mode;
while(stCanMsgReg->can_ctl1.Bits.INITAK != 1); //Initialization mode active
(&stCanMsgReg->can_ctl1)->Bits.CANE = 1;// MSCAN module is enabled
(&stCanMsgReg->can_ctl1)->Bits.LISTEN = 0;
(&stCanMsgReg->can_ctl1)->Bits.WUPM = 1;
#ifdef _PLL_
//If we use OSC clk,set borm to 1;if we use BUS CLK,we should set CLK
(&stCanMsgReg->can_ctl1)->Bits.CLKsrc=1;//assume the bus clk is 48M hz.
(&stCanMsgReg->can_btr0)->Byte = 0xC0| baudrate;// SJW = 4, fcan=48M/4=12M
(&stCanMsgReg->can_btr1)->Byte = 0x6f;// SAMP = 0, TSEG2 = 7, TSEG1 = 16, 24 Tq per bit, Baud=12M/24=500K
#else
(&stCanMsgReg->can_ctl1)->Bits.CLKsrc=0;//MSCAN clock source is the oscillator clock.
(&stCanMsgReg->can_btr0)->Byte = 0x41;//250k
(&stCanMsgReg->can_btr1)->Byte = 0x14;// SAMP = 0, TSEG2 = 2, TSEG1 = 5, 8 Tq per bit
#endif
//(&stCanMsgReg->can_ctl1)->Bits.BORM = 1; //Bus-off recovery upon user request
(&stCanMsgReg->can_ctl1)->Bits.BORM = 0; //Bus-off automatic recovery
(&stCanMsgReg->can_idac)->MergedBits.grpIDAM = 0b00; //2*32bit
(&stCanMsgReg->can_idmr0)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr1)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr2)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr3)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr4)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr5)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr6)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_idmr7)->Byte = 0xff;// filter acceptance/mask
(&stCanMsgReg->can_ctl0)->Byte = 0x00;//clear INITRQ
while((&stCanMsgReg->can_ctl1)->Bits.INITAK != 0);
(&stCanMsgReg->can_ctl0)->Byte = 0x00;// clear INITRQ
(&stCanMsgReg->can_rier)->Byte = 0x01;// receive interrupts
(&stCanMsgReg->can_tier)->Byte = 0x00;// transmit interrupts
while(stCanMsgReg->can_ctl0.Bits.SYNCH != 1); // wait for MSCAN to synchronize
(u8*)(stXGCANStruct->tx_status) = 0x00;
return;
}
They are 2 different code.
1.CANE is write once register.
I can delete "(&stCanMsgReg->can_ctl1)->Bits.CANE = 1;// MSCAN module is enabled ",but "(&stCanMsgReg->can_ctl1)->Bits.LISTEN = 0" still operate register can_ctl1 and it affects also CANE bit,which means it write CANE second time.
My comprehend is right here?
2.Since "They are 2 different code.", I must initializate CAN moudle again in application.Here whether I have any other way?