知恵袋での質問: https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q14219999289
Mbedからのエラー
++ MbedOS Fault Handler ++
FaultType: HardFault
Context:
R0 : 20000474
R1 : 00000002
R2 : 08005900
R3 : 200007E8
R4 : 200005B8
R5 : 0000000F
R6 : 20000B80
R7 : 20000E8C
R8 : FFFFFFFF
R9 : 20000E8C
R10 : FFFFFFFE
R11 : 0800AD8C
R12 : 40013C08
SP : 2001FE90
LR : FFFFFFE9
PC : 08005900
xPSR : 20000027
PSP : 00000000
MSP : 2001FE70
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000000
BFSR : 00000000
UFSR : 00000002
DFSR : 00000008
AFSR : 00000000
Mode : Handler
Priv : Privileged
Stack: MSP
-- MbedOS Fault Handler --
++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x80079FB
Error Value: 0x8005900
For more info, visit: https://armmbed.github.io/mbedos-error/?error=0x80FF013D
-- MbedOS Error Info --
ソースコード
#include "mbed.h"
//pwm信号
PwmOut out1(D5);
PwmOut out2(D9);
//立下り割り込み
InterruptIn HLin1(D7);
InterruptIn HLin2(D4);
InterruptIn SSBT(USER_BUTTON);//ボタン割り込み
Timer downT;
Ticker timer;
Serial xbee(A0,A1);
//ISコマンド
const char IS[19]= {0x7E,0x00,0x0F,0x17,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFE,0x02,0x49,0x53,0x4E};
//グローバル変数
int c=0,d=0,BT=0,cnt=0;
double pw = 1.0;
float oldT = 0,newT = 0,sum = 0,vtimer[10],avg = 0;
bool onoff = false;
char val300[300]="";
int size = 0;
char val[3]="";char val1g[5]="";char val2g[5]="";char val3g[5]="";
//変数Re0
void Re0(){
downT.reset();
sum = 0;
oldT = 0;
newT = 0;
cnt = 0;
c = 0;
d = 0;
downT.start();
}
//デューティー比UP
void UpDuty(){
BT += 10;
if(BT <= 100){
pw = pw - 0.1;
printf("\rDuty: %d[%%]\n\r",BT);
}else if(BT > 100){
BT = 0;
pw = 1.0;
printf("\rDuty: %d[%%]\n\r",BT);
}
}
//立下り割り込み
void low() {
//回数カウント用
c++;
if(c == 64){
d++;
c = 0;
if(d == 19){
newT = downT.read();
vtimer[cnt] = newT - oldT;
oldT = newT;
cnt++;
d = 0;
}
}
}
//ボタン割り込み
void BTH(){
onoff = true;
wait_ms(5);
UpDuty();
Re0();
}
double vconv(double val){
double ans;
ans=1.17*val/1024;
return ans;
}
//通信兼main
int main(){
xbee.baud(9600);
HLin1.fall(&low);
HLin2.fall(&low);
SSBT.rise(&BTH);
downT.start();
//timer.attach(&submit, 1);
bool flag=false;
int a=0,b=0,k=0,timeout = 0;
SSBT.rise(&BTH);
while(1){
//printf("%1.1f,",pw);
//通信
if(xbee.readable() == 0 && flag == false){
for(int i=0;i<19;i++){
xbee.putc(IS[i]);
}timeout=0;
flag = true;
}else if (xbee.readable() == 1 && flag == true){
timeout=0;
size += sprintf(val,"%02x",xbee.getc());
strcat(val300,val);
}else if(xbee.readable() == 0 && flag == true){
timeout++;
if(timeout > 300000 && size < 58){
timeout = 0;
flag = false;
}else if(timeout < 300000 && size == 58){
for(a=44;a < (size - 2);){
for(b=0;b<4;b++){
if(b==0)
sprintf(val,"0x%c",val300[a]);
else
sprintf(val,"%c",val300[a]);
if(k==0){strcat(val1g,val);}
else if(k==1){strcat(val2g,val);}
else if(k==2){strcat(val3g,val);}
a++;
}k++;
}k=0;
size = 0;
flag=false;
}
}
//モーター
if(cnt == 100){
for(cnt=0;cnt<100;cnt++){
sum += vtimer[cnt];
}
avg = sum / 100;
printf("100avg = %f[s] | 100sum = %f[s] | speed = %f[rps]\n\r,x=%lf[mv], y=%lf[mv], z=%lf[mv]\r\n"
,avg,sum,1/avg,vconv(atof(val1g)),vconv(atof(val2g)),vconv(atof(val3g)));
UpDuty();
Re0();
}else if(cnt < 100){
out1.write(pw);
out2.write(1.0);
}
}
}