下面是代码,
1. 首先板子只焊接了一个32M晶振,并没有焊接32K的晶振,
2. I2C有同时在工作,
3. 实在不明白为什么会在PRINT附近单片机死机,这种现象非常频繁,几分钟就出现。
麻烦大大给个思路,帮忙看看
int main(void)
{
uint8_t loopcount, len, i, s;
#if(defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
PWR_DCDCCfg(ENABLE);
#endif
SetSysClock(CLK_SOURCE_PLL_60MHz);
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
#endif
//LED GPIO init
GPIOB_SetBits(GPIO_Pin_15);
GPIOB_ModeCfg(GPIO_Pin_15, GPIO_ModeOut_PP_5mA);
//UART3 Tx Port Configure
GPIOA_SetBits(bTXD3);
GPIOA_ModeCfg(bTXD3, GPIO_ModeOut_PP_5mA);
//UART3 Rx Port Configure
GPIOA_SetBits(bRXD3);
GPIOA_ModeCfg(bRXD3, GPIO_ModeIN_PU);
UART3_DefInit();
PRINT("Welcome to Datan Mocap\r\n"); //{"cmd":"calibration"}
}
__INTERRUPT
__HIGH_CODE
void UART3_IRQHandler(void)
{
volatile uint8_t len, i;
volatile uint16_t crc;
switch(UART3_GetITFlag())
{
case UART_II_LINE_STAT:
{
UART3_GetLinSTA();
break;
}
case UART_II_RECV_RDY:
case UART_II_RECV_TOUT:
len = UART3_RecvString(RxData);
for(i = 0; i < len; i++)
{
if(RxData[i] == '{')
{
Jsonindex = 0;
}
else
{
Jsonindex++;
}
JsonBuf[Jsonindex] = RxData[i];
if(RxData[i] == '}')
{
mode = 1;
}
}
for(i = 0; i < len; i++)
{
//handle receive Calibration
if (calcount == 0 && RxData[i] != 117) {
// first byte must be 117
return;
}
if (calcount == 1 && RxData[i] != 84) {
// second byte must be 84
calcount = 0;
return;
}
calcount++;
// store this byte
caldata[calcount] = RxData[i];
if (calcount < 68) {
// full calibration message is 68 bytes
return;
}
// verify the crc16 check
crc = 0xFFFF;
for (i=0; i < 68; i++) {
crc = crc16_update(crc, caldata[i]);
}
if (crc == 0) {
// data looks good, use it
float offsets[16];
memcpy(offsets, caldata+2, 16*4);
accel_zerog[0] = offsets[0];
accel_zerog[1] = offsets[1];
accel_zerog[2] = offsets[2];
gyro_zerorate[0] = offsets[3];
gyro_zerorate[1] = offsets[4];
gyro_zerorate[2] = offsets[5];
mag_hardiron[0] = offsets[6];
mag_hardiron[1] = offsets[7];
mag_hardiron[2] = offsets[8];
mag_field = offsets[9];
mag_softiron[0] = offsets[10];
mag_softiron[1] = offsets[13];
mag_softiron[2] = offsets[14];
mag_softiron[3] = offsets[13];
mag_softiron[4] = offsets[11];
mag_softiron[5] = offsets[15];
mag_softiron[6] = offsets[14];
mag_softiron[7] = offsets[15];
mag_softiron[8] = offsets[12];
calcount = 0;
saveCalibrationMark = 1;
return;
}
// look for the 117,84 in the data, before discarding
for (i=2; i < 67; i++)
{
if (caldata[i] == 117 && caldata[i+1] == 84)
{
// found possible start within data
calcount = 68 - i;
memmove(caldata, caldata + i, calcount);
return;
}
}
// look for 117 in last byte
if (caldata[67] == 117)
{
caldata[0] = 117;
calcount = 1;
}
else
{
calcount = 0;
}
}
break;
case UART_II_THR_EMPTY:
break;
case UART_II_MODEM_CHG:
break;
default:
break;
}
}