AnsweredAssumed Answered

Can bus not receiving any messages from PCAN

Question asked by ABCD on Jan 8, 2015
Latest reply on Feb 27, 2015 by rsp.rsp

Ich benutze STM32 Cube HAL driver auf STM32F429 für CAN bus communication zwischen Microcontroller und PCAN View.Ich kann sendet die Nachricten zu PCAn aber kann ich nicht empfangt jedes nachrichten von PCAN.Meine Program ist hier:..Danke

035./* Includes ----------------------*/
036.#include "stm32f4xx_hal.h"
037.
038./* USER CODE BEGIN Includes */
039.
040./* USER CODE END Includes */
041.
042./* Private variables ---------------------*/
043.CAN_HandleTypeDef hcan1;
044.CAN_HandleTypeDef hcan2;
045.
046./* USER CODE BEGIN PV */
047.
048./* USER CODE END PV */
049.
050./* Private function prototypes -------------------*/
051.void SystemClock_Config(void);
052.static void MX_GPIO_Init(void);
053.static void MX_CAN1_Init(void);
054.static void MX_CAN2_Init(void);
055.static void CAN2_RX0_IRQHandler(void);
056.
057./* USER CODE BEGIN PFP */
058.
059./* USER CODE END PFP */
060.
061./* USER CODE BEGIN 0 */
062.
063./* USER CODE END 0 */
064.
065.int main(void)
066.{
067.
068. /* USER CODE BEGIN 1 */
069.
070. /* USER CODE END 1 */
071.
072. /* MCU Configuration----------------------*/
073.
074. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
075. HAL_Init();
076.
077. /* Configure the system clock */
078. SystemClock_Config();
079.
080. /* Initialize all configured peripherals */
081. MX_GPIO_Init();
082.
083. MX_CAN1_Init();
084.
085.
086. MX_CAN2_Init();
087.
088.
089.
090. /* USER CODE BEGIN 2 */
091.
092. GPIO_InitTypeDef GPIO_Initpins;
093.
094. GPIO_Initpins.Mode = GPIO_MODE_OUTPUT_PP ;
095. GPIO_Initpins.Pin = GPIO_PIN_5|GPIO_PIN_7;
096. GPIO_Initpins.Pull = GPIO_NOPULL ;
097. GPIO_Initpins.Speed = GPIO_SPEED_LOW;
098. HAL_GPIO_Init(GPIOD, &GPIO_Initpins);
099.
100. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_5|GPIO_PIN_7, GPIO_PIN_SET);
101. /* USER CODE END 2 */
102.
103. /* USER CODE BEGIN 3 */
104. /* Infinite loop */
105. CanTxMsgTypeDef TxMess;
106.
107. TxMess.StdId = 0x123;
108. //TxMess.ExtId = 0x13375000;
109. TxMess.DLC = 0x1;
110. TxMess.Data0 = 0xAA;
111. TxMess.IDE = CAN_ID_STD ;
112. TxMess.RTR = CAN_RTR_DATA;
113. hcan2.pTxMsg = &TxMess;
114.
115.//HAL_CAN_Transmit(&hcan2,50);
116.
117.CanRxMsgTypeDef rmess;
118.
119.rmess.FIFONumber = CAN_FIFO0;
120.rmess.FMI = 14;
121.rmess.IDE = CAN_ID_STD;
122.hcan2.pRxMsg = &rmess;
123.
124.
125.HAL_CAN_Receive_IT(&hcan2,CAN_FIFO0);
126.
127.
128.
129.while(1)
130.{
131. HAL_CAN_Receive(&hcan2,CAN_FIFO0,0);
132. HAL_Delay(50);
133.}
134. /* USER CODE END 3 */
135.
136.}
137.
138./** System Clock Configuration
139.*/
140.void SystemClock_Config(void)
141.{
142.
143. RCC_OscInitTypeDef RCC_OscInitStruct;
144. RCC_ClkInitTypeDef RCC_ClkInitStruct;
145.
146. __PWR_CLK_ENABLE();
147.
148. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
149.
150. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
151. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
152. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
153. HAL_RCC_OscConfig(&RCC_OscInitStruct);
154.
155. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
156. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
157. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
158. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
159. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
160. HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
161.
162.}
163.
164./* CAN1 init function */
165.void MX_CAN1_Init(void)
166.{
167.
168. hcan1.Instance = CAN1;
169. hcan1.Init.Prescaler = 2;
170. hcan1.Init.Mode = CAN_MODE_NORMAL;
171. hcan1.Init.SJW = CAN_SJW_1TQ;
172. hcan1.Init.BS1 = CAN_BS1_5TQ;
173. hcan1.Init.BS2 = CAN_BS2_2TQ;
174. hcan1.Init.TTCM = DISABLE;
175. hcan1.Init.ABOM = DISABLE;
176. hcan1.Init.AWUM = DISABLE;
177. hcan1.Init.NART = DISABLE;
178. hcan1.Init.RFLM = DISABLE;
179. hcan1.Init.TXFP = DISABLE;
180. HAL_CAN_Init(&hcan1);
181.
182.
183.
184.}
185.
186./* CAN2 init function */
187.void MX_CAN2_Init(void)
188.{
189.
190. hcan2.Instance = CAN2;
191. hcan2.Init.Prescaler = 2;
192. hcan2.Init.Mode = CAN_MODE_NORMAL;
193. hcan2.Init.SJW = CAN_SJW_1TQ;
194. hcan2.Init.BS1 = CAN_BS1_5TQ;
195. hcan2.Init.BS2 = CAN_BS2_2TQ;
196. hcan2.Init.TTCM = DISABLE;
197. hcan2.Init.ABOM = DISABLE;
198. hcan2.Init.AWUM = DISABLE;
199. hcan2.Init.NART = DISABLE;
200. hcan2.Init.RFLM = DISABLE;
201. hcan2.Init.TXFP = DISABLE;
202. HAL_CAN_Init(&hcan2);
203.
204.
205.CAN_FilterConfTypeDef sFilterConfig;
206.sFilterConfig.FilterActivation = ENABLE;
207.sFilterConfig.FilterNumber = 14;
208.sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
209.sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;
210.sFilterConfig.FilterIdHigh = 0x00;
211.sFilterConfig.FilterIdLow = 0x00;
212.sFilterConfig.FilterMaskIdHigh = 0x00;
213.sFilterConfig.FilterMaskIdLow = 0x00;
214.sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
215.HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig);
216.
217.}
218.
219./** Configure pins as
220. * Analog
221. * Input
222. * Output
223. * EVENT_OUT
224. * EXTI
225.*/
226.void MX_GPIO_Init(void)
227.{
228.
229. /* GPIO Ports Clock Enable */
230. __GPIOH_CLK_ENABLE();
231. __GPIOB_CLK_ENABLE();
232. __GPIOA_CLK_ENABLE();
233. __GPIOD_CLK_ENABLE();
234.}

Outcomes