大家好,我现在急需要大家的帮助,在调试XDP512的过程中,遇到了一个很奇怪的问题.
要求总线速率是250kps,我用的晶振是无源12MHZ的晶体,在BDM调试时,其上的AD,IO等功能均调试
成功,但在总线调试时却遇到了一个大问题.为实现250kps的速率,即位时间为4us,我选用4分频,同步跳转宽
度为1TQ,时间段1为6TQ,时间段2为5TQ,选用外部晶振.标准帧,发送0x55数据,但却不成功.总线分析仪却检
测不到任何信息,总线负载显示为 86%,用示波器检测发现总线波形是对的,所发送的数据无误.但位时间却
19us左右,这是为什么呢?请大家帮帮忙.项目要交了,压力太大了.
我分析可能是:1.是否是因为在BDM调试状态下,造成非实时呢?
2. 波特率设得不对,但检查无误啊
3. 外置晶振偏差太大,这可从来未遇到过,还有如果是晶振的问题,如何检测呢?
谢谢
CANCTL1 &= 0xbf;
(须在CAN初始化状态下执行)
[此贴子已经被作者于2009-5-30 10:10:29编辑过]
应该可以了。
[此贴子已经被作者于2009-5-30 10:04:51编辑过]
感谢fish1330的观注.
以下是我的程序:
/* Acceptance Code Definitions */
#define ACC_CODE_ID100 0x2000
#define ACC_CODE_ID100_HIGH ((ACC_CODE_ID100&0xFF00)>>8)
#define ACC_CODE_ID100_LOW (ACC_CODE_ID100&0x00FF)
/*switch information*/
#define Switch_ID111 0x111
#define Switch_ID111_HIGH ((Switch_ID111&0xFF00)>>8)
#define Switch_ID111_LOW (Switch_ID111&0x00FF)
/*Check information*/
#define Check_ID241 0x241
#define Check_ID241_HIGH ((Check_ID241&0xFF00)>>8)
#define Check_ID241_LOW (Check_ID241&0x00FF)
/*Velocity information*/
#define Velocity_ID421 0x421
#define Velocity_ID421_HIGH ((Velocity_ID421&0xFF00)>>8)
#define Velocity_ID421_LOW (Velocity_ID421&0x00FF)
/*Temperature information*/
#define Temperature_ID451 0x451
#define Temperature_ID451_HIGH ((Temperature_ID451&0xFF00)>>8)
#define Temperature_ID451_LOW (Temperature_ID451&0x00FF)
/*CAN0初始化函数*/
void CAN0Initial(void) {
CAN0CTL0 = 0x01; /* Enter Initialization Mode,请求进入初始化模式
* CAN0CTL0 CAN0控制寄存器0,用以请求进入初始化模式
* 0b00000001
* ||||||||__ INITRQ(Enter Initialization Mode)初始化请求位
* |||||||___ SLPRQ(Sleep Mode Request bit)休眠模式请求位
* ||||||____ WUPE(Wake-Up disabled)唤醒允许位
* |||||_____ TIME(Time stamping disabled)定时器允许位
* ||||______ SYNCH(Synchronized Status)同步状态位
* |||_______ CSWAI(CAN not affected by Wait)等待模式下CAN停止控制位
* ||________ RXACT(Receiver Active Status bit)接收数据指示位
* |_________ RXFRM(Received Frame Flag bit)接收帧标志位
*/
while (CAN0CTL1_INITAK==0){};/* Wait for Initialization Mode acknowledge
* INITRQ bit = 1时,表示已进入初始化模式
*/
CAN0CTL1 = 0x80; /* Enable MSCAN module and LoopBack Mode,使能CAN,选择外部时钟,
* CAN0CTL1 CAN0控制寄存器0
* 0b10000000
* ||||||||__ INITAK(Initialization Mode Acknowledge)初始化确认位
* |||||||___ SLPAK(Sleep Mode Acknowledge)休眠模式确认位
* ||||||____ WUPM(Wake-up low-pass filter disabled)
* |||||_____ BORM(Bus-Off Recovery Mode)下线恢复模式控制位
* ||||______ LISTEN(Listen Only Mode disabled)
* |||_______ LOOPB(Loop Back Mode enabled)监控自检模式控制位
* ||________ CLKSRC(Ext Osc/Xtal as Clock Source)时钟源选择位
* |_________ CANE(MSCAN Module enabled)使能CAN总线控制位
*/
CAN0BTR0 = 0x03; /* Synch Jump = 1 Tq clock Cycles,预分频为4
* MSCAN Bus Timing Register 0,总线定时寄存器0
* 0b00000011
* ||||||||__BRP0=1
* |||||||___BRP1=1
* ||||||____BRP2=0
* |||||_____RPP3=0
* ||||______BRP4=0
* |||_______BRP5=0,即预分频为4
* ||________SJW0=0
* |_________SJW1=0,即同步跳转宽度为1Tq
*/
CAN0BTR1 = 0x45; /* Set Number of samples per bit, TSEG1 and TSEG2,设置1和2时间段
* MSCAN Bus Timing Register 1, 总线定时寄存器1
* 0b01000101
* ||||||||__TSEG10=1
* |||||||___TSEG11=0
* ||||||____TSEG12=1
* |||||_____TSEG13=0,即时间段1为6 Tq
* ||||______TSEG20=0
* |||_______TSEG21=0
* ||________TSEG22=1,时间段2宽度为5 Tq
* |_________SAMP=0, 即每位进行1次采样,1时每位进行3次采样
*/
CAN0IDAC = 0x10; /* Set four 16-bit Filters,设置接收控制寄存器,
* MSCAN Identifier Acceptance Control Register
* 0b00010000
* ||||||||__IDHIT0
* |||||||___IDHIT1
* ||||||____IDHIT2,滤波器应用指示位
* |||||_____ Unimplemented
* ||||______IDAM0=1
* |||_______IDAM1=0,即4个16位接收滤波器
* ||________
* |_________>- Unimplemented
*/
/* Acceptance Filters */
CAN0IDAR0 = Switch_ID111_HIGH; //|\ 16 bit Filter 0
CAN0IDMR0 = 0x00; //| \__ Accepts Standard Data Frame Msg
CAN0IDAR1 = Switch_ID111_LOW; //| / with ID 0x111
CAN0IDMR1 = 0x00; //|/
CAN0IDAR2 = Check_ID241_HIGH; //|\ 16 bit Filter 1
CAN0IDMR2 = 0x00; //| \__ Accepts Standard Data Frame Msg
CAN0IDAR3 = Check_ID241_LOW; //| / with ID 0x241
CAN0IDMR3 = 0x00; //|/
CAN0IDAR4 = Velocity_ID421_HIGH; //|\ 16 bit Filter 2
CAN0IDMR4 = 0x00; //| \__ Accepts Standard Data Frame Msg
CAN0IDAR5 = Velocity_ID421_LOW; //| / with ID 0x421
CAN0IDMR5 = 0x00; //|/
CAN0IDAR6 = Temperature_ID451_HIGH; //|\ 16 bit Filter 3
CAN0IDMR6 = 0x00; //| \__ Accepts Standard Data Frame Msg
CAN0IDAR7 = Temperature_ID451_LOW; //| / with ID 0x451
CAN0IDMR7 = 0x00; //|/
CAN0CTL0 = 0x00; /* Exit Initialization Mode Request */
while (CAN0CTL1_INITAK==1){};
/* Wait for
CAN0RIER_RXFIE=1; /*允许CAN0的接收中断*/
}
fish1330所提:
"在初始化函数的最后增加这句话:
CANCTL1 &= 0xbf;
(须在CAN初始化状态下执行)"
是要求选择外部晶振时钟,可我已在初始化程序中置
CAN0CTL1 = 0x80;使能CAN,选择外部晶振时钟了,难道一定要在初始化函数最后一句吗?请教.
发送函数应无问题,因为的发送的数据用示波器能检测到,是正确的.关键问题是位速率不对.让我很奇怪.因为以前没用过此类单片机.不知在BDM调试下与脱机运行是否不同.在PIC单片机的调试状态下,总线发送都很正常.请大家帮我查一下为什么位时间不对的原因.谢谢!
缔造中国最具实力的网络集团,让中国创造改变世界
—— 梭尔梭尔五一建站优惠
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |