新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2021-11-2
- 在线时间
- 3 小时
|
发表于 2021-11-11 11:50:42
|
显示全部楼层
你好题主,帖子我一字不漏地看完了,并且尝试移植并且成功了。遇到一个问题,我在添加初始阿虎状态的时候程序莫名其妙地跑飞了。找了两天没找到原因。网上也没谁遇到过这个问题。一时间不知道如何推进了。
//设置 nod ID
setNodeId(&BatproMaster_Data,0x01);
//设置Can状态
setState(&BatproMaster_Data,Initialisation); //这里过不去
这个例程是下载的你前面提供的例程,断点仿真发现 程序跑飞在这个函数:
UNS8 setState(CO_Data* d, e_nodeState newState)
{
if(newState != d->nodeState){
switch( newState ){
case Initialisation:
{
s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0, 0};
d->nodeState = Initialisation;
switchCommunicationState(d, &newCommunicationState);
/* call user app init callback now. */
/* d->initialisation MUST NOT CALL SetState */
(*d->initialisation)(d);
}
/* Automatic transition - No break statement ! */
/* Transition from Initialisation to Pre_operational */
/* is automatic as defined in DS301. */
/* App don't have to call SetState(d, Pre_operational) */
case Pre_operational:
{
s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0, 1};
d->nodeState = Pre_operational;
switchCommunicationState(d, &newCommunicationState);
(*d->preOperational)(d);
}
break;
case Operational:
if(d->nodeState == Initialisation) return 0xFF;
{
s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1, 0};
d->nodeState = Operational;
newState = Operational;
switchCommunicationState(d, &newCommunicationState); //程序在执行这里的时候直接跑飞了。我没找到原因 直接进入了HardFault_Handler中断,我怀疑是改动指针指向有误。
(*d->operational)(d);
}
break;
case Stopped:
if(d->nodeState == Initialisation) return 0xFF;
{
s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0, 1};
d->nodeState = Stopped;
newState = Stopped;
switchCommunicationState(d, &newCommunicationState);
(*d->stopped)(d);
}
break;
default:
return 0xFF;
}/* end switch case */
}
/* d->nodeState contains the final state */
/* may not be the requested state */
return d->nodeState;
}
主芯片用的STM32F107VC 64K RAM
望大牛指教。 |
|