cancel
Showing results for 
Search instead for 
Did you mean: 

CAN protocol forwarding limits?

JTLGE
Associate II

Hi, 

I would like to forward about 2048 bytes via CAN protocol.

I am using an STML4 and have implemented a solution in which sending an STM transmits in the following way:

void CAN1_Tx()

{

CAN_TxHeaderTypeDef TxHeader;

uint32_t TxMailbox;

uint8_t message = 1;

TxHeader.DLC = 1;

TxHeader.StdId = 0x650;

TxHeader.IDE  = CAN_ID_STD;

TxHeader.RTR = CAN_RTR_DATA;

HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_1);

if( HAL_CAN_AddTxMessage(&hcan1,&TxHeader,&message,&TxMailbox) != HAL_OK)

{

Error_Handler();

}

}

and another that receives and prints the received message on the screen:

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)

{

uint8_t rcvd_msg[9];

char msg[50];

if(HAL_CAN_GetRxMessage(hcan,CAN_RX_FIFO0,&RxHeader,rcvd_msg) != HAL_OK)

{

Error_Handler();

}

if(RxHeader.StdId == 0x650 && RxHeader.RTR == 0 )

{

//This is data frame sent by n1 to n2

sprintf(msg,"Message Received : #%x %d\r\n",rcvd_msg[0],rcvd_msg[7]);

}

else if ( RxHeader.StdId == 0x651 && RxHeader.RTR == 2)

{

//This is a remote frame sent by n1 to n2

Send_response(RxHeader.StdId);

return;

}

else if ( RxHeader.StdId == 0x651 && RxHeader.RTR == 0)

{

sprintf(msg,"Reply Received : %#X\r\n",rcvd_msg[0] << 8 | rcvd_msg[1]);

}

HAL_UART_Transmit(&huart2,(uint8_t*)msg,strlen(msg),HAL_MAX_DELAY);

}

each packet I send can have a maximum of 8 bytes.

If I try to send more packets the program unfortunately stops, I can only send 3 packets at most, probably due to the number of mailboxes.

I have tried sending the messages 1 ms apart but the problem still persists.

How can I dispose of more bytes and receive them correctly with this protocol?

2 REPLIES 2

Probably want to check the FIFO depth before cramming in more data, would be a better way of modulating flow than arbitrary delays.​

C​heck that packets are being accepted at the far end node, and it's not retrying. Review bus traffic with an analyzer.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JTLGE
Associate II

Ok, thank you very much.