Announcements

Equip yourself to optimize PSoc4 MCUs for Evs at the EV Webinar. Click here to register.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 4 Forum Discussions

CY_USER
Level 1
Level 1
5 sign-ins First reply posted First question asked

MCU怎样判断CAN 发送状态。

1、使能发送状态

CY_USER_0-1612256991440.png

if ((CAN_1_INT_SR_REG & CAN_1_TX_MESSAGE_MASK) != 0u)
{
  CANDirve_OnMsgTXIsr();
}

如此配置发现在一帧报文发送完了后,不能进入can的发送中断,

2、能有别的标志位来判断can报文的发送吗,不是太想用发送中断

0 Likes
1 Solution
Vison_Zhang
Moderator
Moderator
Moderator
250 solutions authored 10 likes given 500 replies posted

从配置看不出有问题。按照你的配置,使能能 Message Trasmitted 你需要注意一下几点:

调用 CAN_Start() 之后调用如下 code 将 CAN 中断指向你声明的中断函数 ISR_CAN

/* Set CAN interrupt handler to local routine */

CyIntSetVector(CAN_Rx_ISR_NUMBER, ISR_CAN);

在中断函数中你需要清中断,也就是向中断状态寄存器的相应为写 1 来清楚该 bit, 示例如下(示例是 RX 中断,TX中断类似)

CY_ISR(ISR_CAN)

{
/* Clears Receive Message flag */
CAN_Rx_INT_SR_REG = CAN_Rx_RX_MESSAGE_MASK;

/* Switches status message received */
if ((CAN_Rx_BUF_SR_REG & CAN_RX_MAILBOX_0_SHIFT) != 0u)
{
receiveMailboxNumber = CAN_Rx_RX_MAILBOX_Button;

/* Acknowledges the receipt of a new message */
CAN_Rx_RX_ACK_MESSAGE(CAN_Rx_RX_MAILBOX_Button);
}
}



View solution in original post

0 Likes
1 Reply
Vison_Zhang
Moderator
Moderator
Moderator
250 solutions authored 10 likes given 500 replies posted

从配置看不出有问题。按照你的配置,使能能 Message Trasmitted 你需要注意一下几点:

调用 CAN_Start() 之后调用如下 code 将 CAN 中断指向你声明的中断函数 ISR_CAN

/* Set CAN interrupt handler to local routine */

CyIntSetVector(CAN_Rx_ISR_NUMBER, ISR_CAN);

在中断函数中你需要清中断,也就是向中断状态寄存器的相应为写 1 来清楚该 bit, 示例如下(示例是 RX 中断,TX中断类似)

CY_ISR(ISR_CAN)

{
/* Clears Receive Message flag */
CAN_Rx_INT_SR_REG = CAN_Rx_RX_MESSAGE_MASK;

/* Switches status message received */
if ((CAN_Rx_BUF_SR_REG & CAN_RX_MAILBOX_0_SHIFT) != 0u)
{
receiveMailboxNumber = CAN_Rx_RX_MAILBOX_Button;

/* Acknowledges the receipt of a new message */
CAN_Rx_RX_ACK_MESSAGE(CAN_Rx_RX_MAILBOX_Button);
}
}



0 Likes