2018-06-13 12:06 PM
Hi,
I am using Nucleo-144 connecting CAN RX/TX PD0/PD1 to external CAN transceiver, PEAK.
The function is pretty straight forward. Prepare data then call
HAL_CAN_AddTxMessage() to transmit.
CAN_TxHeaderTypeDef TxHeader;
TxHeader.StdId = 0x321;
TxHeader.ExtId = 0x01; TxHeader.RTR = CAN_RTR_DATA; TxHeader.IDE = CAN_ID_STD; TxHeader.DLC = 2;uint8_t txData[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} ;
HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(m_can, &TxHeader, txData, (uint32_t *)CAN_TX_MAILBOX0);
The
HAL_CAN_AddTxMessage() function bailed out on the CAN_TSR TME0/1/2 are all RESET. From the manual, seems all 3 mailboxes are full.
Why it's always full from the very beginning? How do I control this? __HAL_CAN_CLEAR_FLAG() doesn't have this flag.
/* Check that all the Tx mailboxes are not full */
if (((hcan->Instance->TSR & CAN_TSR_TME0) != RESET) || ((hcan->Instance->TSR & CAN_TSR_TME1) != RESET) || ((hcan->Instance->TSR & CAN_TSR_TME2) != RESET)) {/* Return function status */
return HAL_OK; } else { /* Update error code */ hcan->ErrorCode |= HAL_CAN_ERROR_PARAM;return HAL_ERROR;
}Bit 28 TME2: Transmit mailbox 2 empty
This bit is set by hardware when no transmit request is pending for mailbox 2. Bit 27 TME1: Transmit mailbox 1 empty This bit is set by hardware when no transmit request is pending for mailbox 1. Bit 26 TME0: Transmit mailbox 0 empty This bit is set by hardware when no transmit request is pending for mailbox 0. Note: this post was migrated and contained many threaded conversations, some content may be missing.2018-06-15 06:58 PM
Can you receive messages from the peak unit ?
Its best to get the receiver working first.
________________ Attachments : image002.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxUZ&d=%2Fa%2F0X0000000ayl%2Fm3ilAg.78tRx72SkqfZrPWj4IsXnqIN0i9SzcJ2DVDA&asPdf=falseimage001.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxUe&d=%2Fa%2F0X0000000ayn%2F28fHx2UfYPIQ.664.9F2Jd9NilAZvZwESUqwKo9h53k&asPdf=false2018-06-18 06:37 PM
There are 2 issue I found
1. the bxCAN is in initialization mode since I didn't call HAL_CAN_Start() right. Used to have issue with tick so I commented it out.
2. The HAL_GPIO_Init() function seems dropped the CAN_TX voltage from 3.3 to 2.8. So I commented following code out.
/* Check the Speed parameter */
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed)); /* Configure the IO Speed */ temp = GPIOx->OSPEEDR; temp &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2)); temp |= (GPIO_Init->Speed << (position * 2)); GPIOx->OSPEEDR = temp;Now my issue became the PEAK doesn't get the ACK from STM32. Not sure where to setup it up in STM32.
Thx
2018-06-20 11:39 AM
I finally have it working by setting the clock to 80 MHz and set the bit timing as following. Thx
500 Kbps
CanHandle.Init.SJW = CAN_SJW_1TQ;
CanHandle.Init.BS1 = CAN_BS1_4TQ; CanHandle.Init.BS2 = CAN_BS2_5TQ; CanHandle.Init.Prescaler = 16; Bus clock 80 MHz 80,000,000 / (16 * (1+4+5)) 80,000,000 / (16 * 10) 80,000,000 / 160 = 500k2019-02-27 03:38 AM
The issue is here:
HAL_CAN_AddTxMessage(m_can, &TxHeader, txData, (uint32_t *)CAN_TX_MAILBOX0);
CAN_TX_MAILBOX0 will be the value that HAL_CAN_AddTxMessage will return and not an address you give. try:
uint32_t mail_box;
HAL_CAN_AddTxMessage(m_can, &TxHeader, txData, (uint32_t *)&mail_box);
printf("I've used mailbox %d!", mail_box);
/* if transmission errors/busy bus occured, mail_box could be used with : */
HAL_CAN_AbortTxRequest (&m_can, mail_box);
/* send another msg */
// ...
hope this helps
2019-05-14 07:42 PM
Hi mh_stm,
Can you give me full source code?
But it not work.
I check receive message with: HAL_CAN_GetRxFifoFillLevel(&hcan, CAN_RX_FIFO0)
Thank you so much.