2022-03-06 07:44 PM
I intend to use CAN module in STM32F722ZE Nucleo board, but I have a problem- the CAN module does not work.
I tried to see the example code, but it also is not run.
Anyone has the source code for CAN module in STM32F722ZE Nucleo? ( Loopback or normal mode)
Thank you so much
Solved! Go to Solution.
2022-03-07 05:39 AM
I'm wondering why you're using 18 as CAN prescaler and value 1TQ for BS1 and BS2?
Could you please decrease the prescaler and increase BS1 and BS2 to match your bitrate, then test again?
2022-03-07 12:08 AM
Post configuration clock and can.
Then try simple code:
CAN_FilterTypeDef sFilterConfig;
CAN_TxHeaderTypeDef sCanTxHeader;
CAN_RxHeaderTypeDef sCanRxHeader;
uint8_t TxCanBuf[8];
uint8_t RxCanBuf[8];
uint32_t TxMailbox;
main(void){
...
...
HAL_CAN_Start(&hcan1);
while(true){
TxCanBuf[0]=0;
TxCanBuf[1]=1;
TxCanBuf[2]=2;
TxCanBuf[3]=3;
TxCanBuf[4]=4;
TxCanBuf[5]=5;
TxCanBuf[6]=6;
TxCanBuf[7]=7;
sCanTxHeader.DLC=8;
sCanTxHeader.StdId=0x200;
sCanTxHeader.IDE=CAN_ID_STD;
sCanTxHeader.RTR=CAN_RTR_DATA;
HAL_CAN_AddTxMessage(&hcan1, &sCanTxHeader, TxCanBuf, &TxMailbox);
HAL_Delay(100);
}
2022-03-07 02:17 AM
Hello,
If you are using just your Nucleo without any CAN node connected to the bus, the only mode you can use is Loopback mode.
If you have another CAN node connected to the bus i.e. normal mode (CAN_H/CAN_L), of course you have to use a transceiver with your Nucleo board. If it doesn't work, the first thing to check is your HW: all connections from your CAN_Rx/Tx, transceiver, termination resistors, CAN_H/CAN_L to the second node connected to the bus. The transceiver has to leave standby mode. So, check the transceiver datasheet, there is a pin dedicated for that.
Regarding the examples, you can refer to the examples available in CubeF7:
1- \Projects\STM32756G_EVAL\Examples\CAN\CAN_Loopback : loopback mode.
2- Projects\STM32756G_EVAL\Examples\CAN\CAN_Networking : normal mode.
The examples are compatible with F722, just you have to adapt your clocks and the CAN bitrate configs (BS1/BS2)
Hope this helps.
2022-03-07 02:19 AM
I am using the Loopback mode to test the code for CAN module. The pointer is also passed through "HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox)!= HAL_OK; "
But, the program is looping at "
/* wait transmision complete*/
while(HAL_CAN_GetTxMailboxesFreeLevel(&hcan1)!= 3)
I just use F722ZE Nucleo board, no additional configuration.
I also use STM32 CubeMx to generate the configuration code.
Thank you so much.
2022-03-07 02:22 AM
As stated in the previous comment, you can refer to the example \Projects\STM32756G_EVAL\Examples\CAN\CAN_Loopback : loopback mode available in CubeF7.
2022-03-07 02:23 AM
Hello,
I am using Loop back mode also refer the example code for CAN module at STM32F756G_EVAL.
But it does not work.
2022-03-07 02:44 AM
I also try to copy that project and modify to use F722ZE, but, it isn't successful.
Can you give me a project that work well at F722ZE board?
Thank you so much
2022-03-07 05:39 AM
I'm wondering why you're using 18 as CAN prescaler and value 1TQ for BS1 and BS2?
Could you please decrease the prescaler and increase BS1 and BS2 to match your bitrate, then test again?