cancel
Showing results for 
Search instead for 
Did you mean: 

CanBus Communication Nucleo STM32F446RET and Raspberrypi5 using MCP2515 and TAJ1051/3

OmarAbdulaziz
Visitor

Hello, 

 

I'm working on a canbus project and I'm trying to read some data on the nucleo to confirm that my hardware setup works good since it's not a common use. At this point:

- MCP2515 communication via SPI with the RPI5 and it's well configured. 

- I'm using boards and I'm only doing wire connections and the 120ohm resistors are already on the boards. 

- I'm using can1rx and tx, clock and can configuration attached as screen shots and projects attached. 

- I didn't check the canH canL with the oscilloscope since I don't have one, I'm waiting for the one I just ordered. But I checked the wiring many time. on the RPI5 side it show's that data are sent but no acknoledgment.

- I am trying to check if the Nucleo is receiving data but it's receiving nothing for now (as per my code)

Can you help if there is anything wrong with the setup?

In my case, any different between using the can1 or can2?

 

 

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();
  MX_CAN1_Init();
  /* USER CODE BEGIN 2 */
  HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
  HAL_CAN_Start(&hcan1);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  HAL_GPIO_TogglePin(GPIOA,LD2_Pin);
	  HAL_Delay(1000);
	  count++;
	  printf("sending data!\n");


	  if (HAL_CAN_GetRxFifoFillLevel(&hcan1, CAN_RX_FIFO0) > 0) {
	      printf("CAN message received!\n");
	  }



	  if (HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) < 3) {
	      printf("CAN message transmitted!\n");
	  }
	  pb2_state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2);
	  pb3_state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_3);
	  pc2_state = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_2);
	  pc3_state = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_3);
	  //printf("PA2 (CAN_RX): %d, PA3 (CAN_TX): %d\n", pb2_state, pb3_state);
	  //printf("PC2 (CAN_RX): %d, PC3 (CAN_TX): %d\n", pc2_state, pc3_state);
	  CAN_RxHeaderTypeDef rxHeader;
	  uint8_t rxData[8];
	  if (HAL_CAN_GetRxFifoFillLevel(&hcan1, CAN_RX_FIFO0) > 0) {
	      if (HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &rxHeader, rxData) == HAL_OK) {
	          printf("Received CAN message\n");
	      }
	  }


  }
  /* USER CODE END 3 */
}

 

 

OmarAbdulaziz_0-1739175666201.png

 

0 REPLIES 0