cancel
Showing results for 
Search instead for 
Did you mean: 

Can bus not receiving any messages from PCAN

rm239955
Associate II
Posted on January 08, 2015 at 12:06

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.&sharpinclude ''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.Data

http://test.openstm32.org/0

= 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.}

#stm32f2 #stm32f4 #can #discovery #bxcan #filter
7 REPLIES 7
Amel NASRI
ST Employee
Posted on January 09, 2015 at 12:46

Hi ABCD,

Please use English for your posts in order to get more opportunities for help.

To translate: I'm using STM32Cube HAL driver on STM32F429 for CAN communication between MCU and PCAN View. I can send the data to PCAN but I can't receive any data from PCAN.

So the problem here is in reception side. Is the execution stuck at any level? Are there any error flags?

Then when checking the code, I see there are the following calls for both HAL_CAN_Receive_IT & HAL_CAN_Receive.

So, you have first to choose: use interrupt or polling.

If you will use interrupts, you have to properly configure them.

If you will use polling, the timeout value has to be different from ''0'' otherwise there will be a timeout error.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 09, 2015 at 13:26

Are there two functional nodes on the bus, and are they at 500 Kbaud?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rm239955
Associate II
Posted on January 12, 2015 at 14:44

Thanks for reply and sorry for my english.Now I am using only polling for receivng messages and I have removed that interrupt and change my timeout value to 10.But still I am not able to receive any messages from PCAN device.The problem is that while debugging,I checked step by step and the program is running in a continous loop for timout cindition and it doesnt go to the ext condition.Below I have attched the code for timeout condition from stm32f4xx_hal_can.c

 while(__HAL_CAN_MSG_PENDING(hcan, FIFONumber) == 0)

  {

    /* Check for the Timeout */

    if(Timeout != HAL_MAX_DELAY)

    {

      if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))

      {

        hcan->State = HAL_CAN_STATE_TIMEOUT;

        /* Process unlocked */

        __HAL_UNLOCK(hcan);

        return HAL_TIMEOUT;

      }

    }

  }

rm239955
Associate II
Posted on January 12, 2015 at 14:49

No there is only one functional node and I am using PCAN with microcontroller to send and receive messgaes.Both are kept at 500KBaud

rs2
Associate II
Posted on February 27, 2015 at 10:37

Hello, I am having exactly the same problem. I can send frames (see them with PCANView) but I can not receive the frames sent with PCANview to the firmware.

I am using the last version STM32Cube_FW_F4_V1.4.0.

Did you find a solution? Is it a bug?

Thanks in advance!

salehi
Associate
Posted on August 24, 2016 at 16:40

Hi ST, 

thanx for attention

i'm using STM32F107 for Send and Receive data between 2 board ,they are designed in CAN protocol. (both of them are STM32F107RCT)

i succeed to send data and watch that on oscilloscope and DATA[8] register on debuging mode ,,,,,,  but i can't get that on receive board when i debug and watch DATA[8] register on receiver (Slave) micro.

my initialization program for receiver micro is :

void MX_CAN1_Init(void)

{

  CAN_FilterConfTypeDef  sFilterConfig;

  

  static CanTxMsgTypeDef        TxMessage;

  static CanRxMsgTypeDef        RxMessage;

  hcan1.pTxMsg = &TxMessage;

  hcan1.pRxMsg = &RxMessage;

  hcan1.Instance = CAN1;

                RxMessage.FIFONumber = CAN_FIFO0; 

RxMessage.FMI = 14; 

RxMessage.IDE = CAN_ID_STD; 

hcan1.pRxMsg = &RxMessage ;

hcan1.pRxMsg->StdId=0x12;

hcan1.pRxMsg->ExtId=0x12; 

hcan1.pRxMsg->IDE=CAN_ID_STD; 

hcan1.pRxMsg->RTR=CAN_RTR_DATA;

hcan1.pRxMsg->DLC=8;

        hcan1.Init.Prescaler = 16;

hcan1.Init.Mode = CAN_MODE_LOOPBACK;

hcan1.Init.SJW = CAN_SJW_1TQ;

hcan1.Init.BS1 = CAN_BS1_8TQ;

hcan1.Init.BS2 = CAN_BS2_1TQ;

hcan1.Init.TTCM = DISABLE;

hcan1.Init.ABOM = ENABLE;

hcan1.Init.AWUM = ENABLE;

hcan1.Init.NART = DISABLE;

hcan1.Init.RFLM = DISABLE;

hcan1.Init.TXFP = ENABLE;

  if (HAL_CAN_Init(&hcan1) != HAL_OK)

  {

    Error_Handler();

  }

///////////////////////////////////////////////////filter begin

 

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_FIFO0;

  sFilterConfig.FilterActivation = ENABLE;

  sFilterConfig.BankNumber = 14;

  if (HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig) != HAL_OK)

  {

    /* Filter configuration Error */

    Error_Handler();

  }

//////////////////////////////////////////////////////filter end

}

and in while : 

while (1)

  {

    HAL_CAN_Receive( &hcan1,  CAN_FIFO0,  50);

    HAL_Delay(50);

}

please help me to find

my fault

thanx

AlirezaSalehi

salehi.general@yahoo.com
Posted on August 24, 2016 at 17:11

Show the code you are debugging!!! Remember I don't have a crystal ball, show enough code that I can see what is happening. I don't work for ST, there are minimal staff here.

What clocks and baud rates are you using here?

hcan1.Init.Mode = CAN_MODE_LOOPBACK; // Probably don't want to use loop-back if you want two nodes to communicate properly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..