2023-11-13 03:40 AM
Hello everyone. The last time I opened a form related to bit timing, I realized that the problem was in the Canbus transceiver. I added 1-2 revisions and replaced it with the MCP2551 transceiver. Even though there is a device on the other side, I get an acknowledgment error and the logic analyzer is as follows.
Solved! Go to Solution.
2023-11-22 01:04 AM
Solution: First, I changed the CAN2 mode to loopback and tried to receive data, but I could not receive it. Then I edited the time segment 1 and 2 values and after receiving the data in loopback mode, I tried normal mode and my system worked.
2023-11-13 06:56 AM
On the CAN bus, connect CANH with CANH, and CANL with CANL.
Then maybe remove one of the 120R resistors.
2023-11-13 08:42 AM - edited 2023-11-13 08:44 AM
Thanks for your support, I will give you feedback when I try it
2023-11-13 09:43 PM
unfortunately it didn't work
2023-11-13 09:47 PM
2023-11-14 01:57 PM
Post some code
2023-11-15 04:34 AM - edited 2023-11-15 04:34 AM
Transmit
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CAN2_Init();
/* USER CODE BEGIN 2 */
HAL_CAN_Start(&hcan2);
TxHeader.DLC = 1;
TxHeader.IDE = CAN_ID_STD;
TxHeader.RTR = CAN_RTR_DATA;
TxHeader.StdId = 0x407;
TxData[0] = 0xFA;
HAL_CAN_ActivateNotification(&hcan2,CAN_IT_RX_FIFO0_MSG_PENDING);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
// int state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);
// if(state){
HAL_CAN_AddTxMessage(&hcan2,&TxHeader,TxData,&TxMailbox);
// HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13,GPIO_PIN_SET);
// }
// else{
// HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13,GPIO_PIN_RESET);
// }
HAL_Delay(200);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2023-11-15 04:35 AM
Receiver
/* USER CODE BEGIN Includes */
CAN_RxHeaderTypeDef RxHeader;
uint8_t RxData[2];
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
CAN_HandleTypeDef hcan;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_CAN_Init(void);
/* USER CODE BEGIN PFP */
void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan){
HAL_CAN_GetRxMessage(hcan,CAN_RX_FIFO0,&RxHeader,RxData);
}
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CAN_Init();
/* USER CODE BEGIN 2 */
HAL_CAN_Start(&hcan);
HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2023-11-16 02:05 AM
> I found the problem. The message is going to the other party's RX line incorrectly.
What do you exactly mean? Some hardware wiring problem?
2023-11-16 08:09 AM
Edit your post and use Code Sample so it formats your code which makes it easier to read your code