cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-Disco + SN65HVD230 CAN Connection

cbodie
Visitor

I am trying to use the CAN Peripheral on my STM32F746G-Disco board. I am using a Waveshare SN65HVD230 transceiver from Amazon. I have built a working CAN bus and verified that messages are being sent 1 per second, using a USB Peak Can.  

cbodie_0-1754576049743.png

When I try and send a message from the STM32Board it is not being picked up on the Peak can.

The code works fine in LOOPBACK mode but in NORMAL it isnt working. 

Here is a scope capture from the Rx pin on the can transceiver. 

cbodie_1-1754576336725.jpeg

 

Main function code

int main(void)
{

  /* USER CODE BEGIN 1 */
  setvbuf(stdin, NULL, _IONBF,0);

  /* 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();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CAN1_Init();
  MX_USART1_UART_Init();

  CAN_FilterTypeDef canfilter;
  canfilter.FilterActivation = CAN_FILTER_ENABLE;
  canfilter.FilterBank = 0;
  canfilter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
  canfilter.FilterIdHigh = 0x0000;
  canfilter.FilterIdLow = 0x0000;
  canfilter.FilterMaskIdHigh = 0x0000;
  canfilter.FilterMaskIdLow = 0x0000;
  canfilter.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilter.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilter.SlaveStartFilterBank = 0; // Only needed for dual CANs

  HAL_CAN_ConfigFilter(&hcan1, &canfilter);

  if(HAL_CAN_Start(&hcan1) != HAL_OK){
	  Error_Handler();
  }

  CAN_TxHeaderTypeDef TxHeader;
  CAN_RxHeaderTypeDef RxHeader;
  uint8_t TxData[8] = "HELLOCAN";
  uint8_t RxData[8];
  uint32_t TxMailbox;

  	TxHeader.DLC = 8;             // Data length
    TxHeader.IDE = CAN_ID_STD;   // Standard ID
    TxHeader.RTR = CAN_RTR_DATA; // Data frame
    TxHeader.StdId = 0x321;      // CAN ID

    // Transmit message
    if (HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox) != HAL_OK) {
      Error_Handler();
    }

    // Wait for message to be received (polling version)
    while (HAL_CAN_GetRxFifoFillLevel(&hcan1, CAN_RX_FIFO0) == 0);

    if (HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK) {
      Error_Handler();
    } else {
    	HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
    }

 

Here is my ioc config

cbodie_2-1754581237848.png

cbodie_4-1754581283533.png

 

Any help is greatly apricated! Thank you

 

0 REPLIES 0