最近在使用一款STM32F042K6T6的片子在做充电器与锂电池的项目,在通信过程发现有个别数据帧中发生了错误,并产生了错误中断,TEC寄存器在累加。 通过使用示波器观察通信波形,发现在发送数据过程中,有个别数据帧被从中间截断,没有完整发送一帧数据。因为打开了自动重传功能,所以马上又重发了一帧。但也有可能一直处于重传模式,无法进行正常通信。各位大神,麻烦帮忙指点一二,到底是什么情况会引起如下错误。具体波形如下: åçäºä¸æ¬¡é误并éä¼ 发生错误时的波形 é误帧å±å¼ 错误帧展开 éä¼ å¸§ 重传了一帧正常数据 圈出来的为全部错误,后面才重传正常。 电路原理图 |
【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?
CAN收发都是使用中断方式。以下是配置代码,接收数据我是在接收中断callback里面采集。
#include "userdefine.h"
#include "stm32f0xx_hal_can.h"
CANReceiveDataTypeDef CAN_RXData;
CANComTypeDef CAN_Com; //CAN½á¹¹ÌåÉùÃ÷
/* USER CODE END 0 */
CAN_HandleTypeDef hcan;
/* CAN init function */
void MX_CAN_Init(void)
{
hcan.Instance = CAN;
hcan.Init.Prescaler = 8;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SJW = CAN_SJW_1TQ;
hcan.Init.BS1 = CAN_BS1_5TQ;
hcan.Init.BS2 = CAN_BS2_6TQ;
hcan.Init.TTCM = DISABLE;
hcan.Init.ABOM = DISABLE;
hcan.Init.AWUM = DISABLE;
hcan.Init.NART = DISABLE;
hcan.Init.RFLM = DISABLE;
hcan.Init.TXFP = DISABLE;
HAL_CAN_Init(&hcan);
}
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(hcan->Instance==CAN)
{
/* USER CODE BEGIN CAN_MspInit 0 */
/* USER CODE END CAN_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_CAN1_CLK_ENABLE();
/**CAN GPIO Configuration
PA11 ------> CAN_RX
PA12 ------> CAN_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_CAN;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN CAN_MspInit 1 */
/* USER CODE END CAN_MspInit 1 */
}
}
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
{
if(hcan->Instance==CAN)
{
/* USER CODE BEGIN CAN_MspDeInit 0 */
/* USER CODE END CAN_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_CAN1_CLK_DISABLE();
/**CAN GPIO Configuration
PA11 ------> CAN_RX
PA12 ------> CAN_TX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
/* Peripheral interrupt Deinit*/
HAL_NVIC_DisableIRQ(CEC_CAN_IRQn);
}
/* USER CODE BEGIN CAN_MspDeInit 1 */
/* USER CODE END CAN_MspDeInit 1 */
}
/* USER CODE BEGIN 1 */
/***********************************************
************************************************/
void CAN_Config(void)
{
CAN_FilterConfTypeDef sFilterConfig;
static CanTxMsgTypeDef TxMessage;
static CanRxMsgTypeDef RxMessage;
/*##-1- Configure the CAN peripheral #######################################*/
hcan.Instance = CAN;
hcan.pTxMsg = &TxMessage;
hcan.pRxMsg = &RxMessage;
/*##-2- Configure the CAN Filter ###########################################*/
sFilterConfig.FilterNumber = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 14;
if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
{
/* Filter configuration Error */
}
HAL_CAN_Receive_IT(&hcan, CAN_FIFO0); //Æô¶¯CANÖжϣ¬²¢½ÓÊÕÊý¾Ý
}
/***********************************************
************************************************/
uint8_t NOTokNUM = 0x55;
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef *CanHandle)
{
if ((CanHandle->pRxMsg->IDE == CAN_ID_STD) && (CanHandle->pRxMsg->DLC == 8))
{
CAN_Com.CANRXID = CanHandle->pRxMsg->StdId;
for(CAN_Com.CANRxBytesNum = 0;CAN_Com.CANRxBytesNum < 8;CAN_Com.CANRxBytesNum++)
{
CAN_Com.CANRxDataBuf[CAN_Com.CANRxBytesNum] = CanHandle->pRxMsg->Data[CAN_Com.CANRxBytesNum];
}
if((CAN_Com.CANRXID == 0x0207)||(CAN_Com.CANRXID == 0x0217)||(CAN_Com.CANRXID == 0x0227)||(CAN_Com.CANRXID == 0x0237)||
(CAN_Com.CANRXID == 0x0247)||(CAN_Com.CANRXID == 0x0257)||(CAN_Com.CANRXID == 0x0267)||(CAN_Com.CANRXID == 0x02D7)||
(CAN_Com.CANRXID == 0x03FF)||(CAN_Com.CANRXID == 0x03FE))
{
CAN_Com.CANRxNewDataFlage = 1;
ReceiveDataNum = 255; //CANͨÐų¬Ê±¸³³õÖµ 280
}
}
/* Receive */
if (HAL_CAN_Receive_IT(CanHandle, CAN_FIFO0) != HAL_OK)
{
NOTokNUM = 0x99;
/* Reception Error */
}
}
评分
查看全部评分
评分
查看全部评分