2025-08-07 8:44 AM
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.
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.
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
Any help is greatly apricated! Thank you
2025-08-07 12:01 PM
If you can receive CAN messages then transmitting should work as well. You haven't indicated if you scoped the CAN Tx pin from the STM32. Are you sure you have the correct pin connected to the CAN transceiver? There are 4 possible CAN Tx pins that can be used.
2025-08-07 12:31 PM
This is a scope of the Tx pin, going into the can transceiver.
I haven't been able to receive the messages in the code. It gets stuck at the while code line, and doesn't move from it, but I was able to see it on the scope and on the USB PEAK CAN.
The grey wire is Rx and the Purple wire is Tx. I already checked to make sure that the transceiver is getting 3.3V.The top PIN should be PB8 and the one beneath it is PB9 (according to the card that came in the packaging for the STM.
What do you mean by GIGO?