使用的是Keil uVision5,STM32F1向STM32F4发送数据,数据是一个自定义的结构体RTK_OPS_,图方便,直接在STM32F1中强制转换为字符串发送,STM32F4接收到完成字符串数据后,进行强制转换为结构体RTK_OPS_指针,得到完整数据,但是得到的指针数据赋值时却出错HardFault_Handler,这是为什么,是编译问题还有程序不对呢?
自定义的结构体:
typedef struct RTK_GPS_
{
u8 Quality;
double Lat_M;
double Lon_M;
double Alt_M;
double TrackAngle;
double Speed_M;
}RTK_GPS_;
STM32F1发送数据:
void Send_Gps_MCU1(void)
{
#define RTK_GPS_SIZE 48
#define GPS_HEAD_SIZE 3
RTK_GPS_ GPS_Send_Data;
u8 GPS_Head[GPS_HEAD_SIZE] = {'G','P','S'};
GPS_Send_Data.Alt_M = RTK_GPS.Alt_M;
GPS_Send_Data.Lat_M = RTK_GPS.Lat_M;
GPS_Send_Data.Lon_M = RTK_GPS.Lon_M;
GPS_Send_Data.Quality = RTK_GPS.Quality;
GPS_Send_Data.Speed_M = RTK_GPS.Speed_M;
GPS_Send_Data.TrackAngle = RTK_GPS.TrackAngle;
Usart3.Send(GPS_Head,GPS_HEAD_SIZE);
Usart3.Send((u8*)&GPS_Send_Data.Quality,RTK_GPS_SIZE);//STM32F1发送数据
}
STM32F4接收数据:
BOOL RTK_Read( u8 *StrAdd)
{
RTK_GPS_ T1;
RTK_GPS_* RTK_GPS_Temp;
RTK_GPS_Temp = (RTK_GPS_*)StrAdd;
T1= (*RTK_GPS_Temp);//运行到这出错,HardFault_Handler
return True;
}
STM32F1是纯C语言程序,STM32F4是C和C++混合,STM32F4在线调试,通过RTK_GPS_Temp 指针能看到跟STM32F1一样的数据,但是赋值时T1= (*RTK_GPS_Temp),就出错了,跳到HardFault_Handler中断。请问这是什么原因呢。
|