2019-02-11 04:03 AM
2019-02-11 04:59 AM
I don't believe the two are connected, perhaps expand on the detail, with minimal code example, so the issue might be reviewed or replicated.
2019-02-11 08:17 PM
#include "main.h"
#include "stm32f1xx_hal.h"
CAN_HandleTypeDef hcan1;
WWDG_HandleTypeDef hwwdg;
UART_HandleTypeDef huart1;
static CanTxMsgTypeDef myTxMessage;
static CanRxMsgTypeDef myRxMessage;
static CAN_FilterConfTypeDef myFilter;
uint32_t j;
uint8_t *Rcbuff;
uint8_t id,dlc,data[8];
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_WWDG_Init(void);
static void MX_CAN1_Init(void);
static void MX_USART1_UART_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_WWDG_Init();
MX_CAN1_Init();
MX_USART1_UART_Init();
myFilter.FilterNumber = 0;
myFilter.FilterMode = CAN_FILTERMODE_IDMASK;
myFilter.FilterScale = CAN_FILTERSCALE_32BIT;
myFilter.FilterIdHigh = 0x0000;
myFilter.FilterIdLow = 0x0000;
myFilter.FilterMaskIdHigh = 0x0000;
myFilter.FilterMaskIdLow = 0x0000;
myFilter.FilterFIFOAssignment = 0;
myFilter.FilterActivation = ENABLE;
HAL_CAN_ConfigFilter(&hcan1,&myFilter);
hcan1.pTxMsg = &myTxMessage;
myTxMessage.DLC = 8;
myTxMessage.StdId = 0x123;
myTxMessage.IDE = CAN_ID_STD;
myTxMessage.RTR=CAN_RTR_DATA;
myTxMessage.Data[0]=0xAB;
myTxMessage.Data[1]=0xCD;
myTxMessage.Data[2]=0xEF;
myTxMessage.Data[3]=0xAA;
myTxMessage.Data[4]=0xBB;
myTxMessage.Data[5]=0xCC;
myTxMessage.Data[6]=0xDD;
myTxMessage.Data[7]=0xEE;
//HAL_CAN_Transmit_IT(&hcan1);
HAL_Delay(1000);
while (1)
{
Rcbuff=HAL_CAN_Receive_IT(&hcan1,CAN_FIFO0);
HAL_UART_Transmit(&huart1,Rcbuff,15,10);
HAL_Delay(100);
}
}
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
__HAL_UART_ENABLE_IT( &huart1,UART_IT_TXE) ;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL2_ON;
RCC_OscInitStruct.PLL2.PLL2MUL = RCC_PLL2_MUL8;
RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
__HAL_RCC_PLLI2S_ENABLE();
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
static void MX_CAN1_Init(void)
{
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 16;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SJW = CAN_SJW_1TQ;
hcan1.Init.BS1 = CAN_BS1_5TQ;
hcan1.Init.BS2 = CAN_BS2_3TQ;
hcan1.Init.TTCM = DISABLE;
hcan1.Init.ABOM = DISABLE;
hcan1.Init.AWUM = DISABLE;
hcan1.Init.NART = DISABLE;
hcan1.Init.RFLM = DISABLE;
hcan1.Init.TXFP = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
static void MX_WWDG_Init(void)
{
hwwdg.Instance = WWDG;
hwwdg.Init.Prescaler = WWDG_PRESCALER_8;
hwwdg.Init.Window = 0x40;
hwwdg.Init.Counter = 0x40;
hwwdg.Init.EWIMode = WWDG_EWI_DISABLE;
if (HAL_WWDG_Init(&hwwdg) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_WritePin(nCAN2_STB_GPIO_Port, nCAN2_STB_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = HS_LS_IN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(HS_LS_IN_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = S2_IN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(S2_IN_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = nCAN2_STB_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(nCAN2_STB_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = CAN2_ERR_IN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(CAN2_ERR_IN_GPIO_Port, &GPIO_InitStruct);
}
void _Error_Handler(char *file, int line)
{
while(1)
{
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
}
#endif
This is our code.
2019-02-11 08:26 PM
So some arbitrary delays, no interrupt or callback code, doesn't wait/check status and doesn't kick the watchdog.
Turns status to a pointer, outputs data from random pointer.
2019-02-11 08:31 PM
ok.. we will check.. Thank you so much..