2024-03-10 02:32 PM - edited 2024-03-12 04:14 AM
I'm working on a custom board with a F446RET6 and testing through some code bits. I've been able to successfully test that the board programs and functions with a led-blink style program. My problem is that I'm attempting to use CAN2; I'm trying to test via loopback but I'm having issues getting any type of IRQ for a receive. I feel like its something basic I'm missing here but after reading through some other posts I'm either brain-dead or missing something.
Also I understand that the "CAN2" device is really the "slave" to CAN1. I've got my slave start for the filter set to 14 to split everything half and half and just arbitrarily chose bank 15:
hcan2Filter.FilterActivation = ENABLE;
hcan2Filter.FilterIdHigh = 0x0000;
hcan2Filter.FilterIdLow = 0x0000;
hcan2Filter.FilterMaskIdHigh = 0x0000;
hcan2Filter.FilterMaskIdLow = 0x0000;
hcan2Filter.FilterMode = CAN_FILTERMODE_IDMASK;
hcan2Filter.FilterScale = CAN_FILTERSCALE_32BIT;
hcan2Filter.FilterFIFOAssignment = CAN_RX_FIFO1;
hcan2Filter.FilterBank = 15;
hcan2Filter.SlaveStartFilterBank = 14;
Also I have the FIFO1 message pending interrupt set up:
//enable CAN2 interrupt
if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING) != HAL_OK)
{
printf("CAN IRQ enable error\r\n");
Error_Handler();
}
The IRQ function for now just spits out the rx'd ID:
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO1, &RxHeader, RxData) != HAL_OK) //get can message
{
printf("CAN msg RX error\r\n");
Error_Handler();
} //handle any errors if not OK
printf("CAN Message Rx'd from ID %d\r\n", RxHeader.StdId);
return;
}
I've attached my IOC and main, can someone point out what's probably staring me in the face?
Solved! Go to Solution.
2024-03-12 04:32 AM
Yes, I understand how to adjust the CAN timing. My question was on if the CAN-TX pin (PB13) is still exposed in loopback or not. I thought I remembered coming across that it was.
For anyone that comes across this with google, the latest ioc managed to pass loopback after updating the mode. I think when I re-wrote the code I had it and was just fighting a few different things. Some good threads out there explaining better the filtering and banks.
Some other things that tripped me up which i guess was just a cumulative mess:
2024-03-11 02:00 AM
Hello,
Checking your code, you are configuring the CAN in normal mode not in loopback mode.
2024-03-11 06:57 PM
Valid. I had tried to update the same code prior for CAN1 and was having the same issues, I missed that in reverting back. Updated the OP to make clear. Changing to loopback still results in the same issue.
Speaking of loopback, so long as its in "loopback" but not "loopback + silent" the TX pin (PB13) should still be exposed, correct? I'll see if I can slow the bitrate down to something my "dumb" logic analyzer can pick up or not just to test if there's anything getting out at all.
2024-03-12 01:29 AM - edited 2024-03-12 01:30 AM
Hello,
Try to change the following parameters' values:
hcan2.Init.Prescaler = 12;
hcan2.Init.TimeSeg1 = CAN_BS1_3TQ;
hcan2.Init.TimeSeg2 = CAN_BS2_1TQ;
Decrease, the prescaler as much as possible and increase BS1 and BS2 as much as possible to fit your bitrate.
Try for example:
Prescaler = 3
BS1 = 14
BS2 = 5
2024-03-12 04:32 AM
Yes, I understand how to adjust the CAN timing. My question was on if the CAN-TX pin (PB13) is still exposed in loopback or not. I thought I remembered coming across that it was.
For anyone that comes across this with google, the latest ioc managed to pass loopback after updating the mode. I think when I re-wrote the code I had it and was just fighting a few different things. Some good threads out there explaining better the filtering and banks.
Some other things that tripped me up which i guess was just a cumulative mess:
2024-03-12 05:54 AM - edited 2024-03-12 07:08 AM
Hello,
I'm confused... Your first question was regarding the CAN is not working (no message received in the RX callback), now you're asking about the exposal of pin PB13!
The exposal of the Tx pin depends on your configuration:
Silent mode / Loop back mode / Loop back combined with silent mode.
So only in loop back mode the Tx pin is exposed.
Now regarding your comment:
Yes, I understand how to adjust the CAN timing. My question was on if the CAN-TX pin (PB13) is still .
-> It's true that your configuration of the prescaler, BS1 and BS2 gives you your 500kb/s but these values are not recommended as BS1 and BS2 values are low. Since your request was regarding a communication issue I thought about your bitrate configuration. I don't think this is due to a filter config (already checked). That's why I recommended you to change your bitrate settings.