2023-08-28 01:56 AM
Hello !
I am currently trying communication using the CANBUS from a nucleo-f411re to an arduino
I used to work with an MCP2515 (using the CS, MOSI, MISO, SCK pins) and i now want to work with an MCP2551 using the RxCAN and TxCAN pins. My setup looks like this
MCP2515:
- Vss to GND
- Vdd to +5V
- TXD to PA12
- RXD to PA11
- CAN H to CAN H to the arduino (arduino is connected to an mcp2515, it's just a temp module)
- CAN L to CAN L to the arduino
- Vref to 10K ohm resistance to GND
nucleo411re's GND is connected to arduino's GND
I know the problem isn't from the arduino, so it must be either from the pins of the mcp2551, or from the nucleof411re
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
CAN_HandleTypeDef hcan;
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_CAN_Init(void);
/* USER CODE BEGIN PFP */
void CAN_Transmit(uint32_t id, uint8_t *data, uint8_t length);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void CAN_Transmit(uint32_t id, uint8_t *data, uint8_t length)
{
CAN_TxHeaderTypeDef TxHeader;
uint32_t TxMailbox;
TxHeader.StdId = id;
TxHeader.IDE = CAN_ID_STD;
TxHeader.RTR = CAN_RTR_DATA;
TxHeader.DLC = length;
if (HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailbox) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
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_USART2_UART_Init();
MX_CAN_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint8_t *data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
while (1)
{
CAN_Transmit(0x01, data, 8);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Once i run this, i don't get any output from the arduino...
When i mesure the voltage from the RxCAN and TxCAN pin, i get something (about 5V) and on the output of the MCP2551 i also get some (like 2.4V)
I'D like this to work... Thanks for the help in advance !!!
Solved! Go to Solution.
2023-08-30 06:05 PM
The Nucleo-F411RE doesn't have a CAN controller. So how did you even come up with "- TXD to PA12
- RXD to PA11"?
2023-08-28 03:16 AM
Hello @lfresnay ,
Try to find if someone did this previously on the web.
Example: https://github.com/eziya/STM32_SPI_MCP2515
Foued
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.
2023-08-29 06:52 PM
First you say "I know the problem isn't from the arduino, so it must be either from the pins of the mcp2551, or from the nucleof411re", then later you say "Once i run this, i don't get any output from the arduino."
So which statement is correct?
2023-08-30 12:46 AM
Both statements are true, i'm saying that the problem doesn't come from arduino, therefore it doens't print anything, meaning that no information has been received to the arduino, from the mcp2551
2023-08-30 12:52 AM
I had found this repo (which helped me a lot to make the mcp2515 work) but i haven't found anything to make the mcp2551 works with the stm32, i have found with other models but that doesn't really work like the nucleof411re, i am still looking for few days, otherwise i'll stick with the mcp2515 it's not that bad for the moment
2023-08-30 06:05 PM
The Nucleo-F411RE doesn't have a CAN controller. So how did you even come up with "- TXD to PA12
- RXD to PA11"?