Problem Sending CAN Message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2018-04-15 2:27 PM
I am following the example code found here to send and receive CAN messages:
STM32Cube_FW_F4_V1.21.0\Projects\STM324xG_EVAL\Examples\CAN\CAN_Networking\Src
I can happily receive CAN messages but when I call the following code, the CAN message is never sent.
HAL_CAN_AddTxMessage( &hcan1, &TxHeader, TxData, &TxMailbox );
while(HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) != 3) {}TxHeader is configured as:
TxHeader.StdId = 0x123;
TxHeader.ExtId = 0x01; TxHeader.RTR = CAN_RTR_DATA; TxHeader.IDE = CAN_ID_STD; TxHeader.DLC = 7; TxHeader.TransmitGlobalTime = DISABLE;And TxData is filled with seven bytes of data.
HAL_CAN_GetTxMailboxesFreeLevel always returns 2 and I don't see the CAN message on the bus.
Any help or idea would be gratefully appreciated.
Andy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-01-29 12:45 PM
But the data is incorrect ?
Do you have a scope to see the CanBus wires are actually transmitting a packet ?
If you are not sure about this snippet, check it… can you single step ?
uint32_t CheckData = ((uint32_t)aData[3] << CAN_TDL0R_DATA3_Pos) |
((uint32_t)aData[2] << CAN_TDL0R_DATA2_Pos) |
((uint32_t)aData[1] << CAN_TDL0R_DATA1_Pos) |
((uint32_t)aData[0] << CAN_TDL0R_DATA0_Pos);
Do you have a Transmitter and a slave ? You need both for the CanBus to operate.
Do you have a known good transmitter, and you can receive packets ?, this is the best starting point.
I used a CanDo unit. Very easy to start that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-01-29 1:01 PM
Thank you so much for your answers ..
I have no scope to watch bus lines.
When I debug the receive side received value before and after start the system (always) equals to 0x00000001 and some times it takes 0x00000004. But there is no error.(it reads 8 bytes rxData and all of them equals to 0)
I use mcp2551 and Two stm32f407vg if you want to check i can upload the code here (the code is stm32cube's example just can filter configurations are mine).
And also i dont want to steal your time i always feel guilty about "time" when i ask for help thank you again .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-01-29 1:39 PM
You really need a scope…
You must have a known good transmitter and a receiver set to the correct bit rate to make the CanBus operate correctly.
You can see that easily on the scope.
You missed step 1 of 1000 steps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-02-14 4:47 AM
I finally borrow a oscilloscope sorry for delay
when only transmitter side on the bus no another node
by using this script
if ( ( hcan1.Instance->TSR & CAN_TSR_TME0 ) == CAN_TSR_TME0 ) // (1)
{
hcan1.Instance->sTxMailBox[ 0 ].TDTR = 8;
hcan1.Instance->sTxMailBox[ 0 ].TDLR = 0x55555555;
hcan1.Instance->sTxMailBox[ 0 ].TDHR = 0x55555555;
hcan1.Instance->sTxMailBox[ 0 ].TIR = ( ( uint32_t )0x123 << 21 | CAN_TI0R_TXRQ );
}
i get
0 001 0010 0011 0001 000 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 0101 110010101111101111111
when two node on the bus with this script
if ( ( hcan1.Instance->TSR & CAN_TSR_TME0 ) == CAN_TSR_TME0 ) // (1)
{
hcan1.Instance->sTxMailBox[ 0 ].TDTR = 8;
hcan1.Instance->sTxMailBox[ 0 ].TDLR = 0x22222222;
hcan1.Instance->sTxMailBox[ 0 ].TDHR = 0x22222222;
hcan1.Instance->sTxMailBox[ 0 ].TIR = ( ( uint32_t )0x123 << 21 | CAN_TI0R_TXRQ );
}
i get
0 001 0010 0011 0001 000 001000110011001000010111001100011 0010 0010 0010 0010 0010 0010 0010 0010 11010001100111111
thank you. Best Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-02-14 11:18 AM
Do you have a known good dongle ?
Send packets every 1second and work on the receiver.
Then you can work on transmitter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2022-08-24 7:24 AM
Hi,
Did you solve the transmit error caused by not receiving ACK? If you solved it, can you please tell me your solution, I am using the same transciever and stm card as you

- « Previous
- Next »