-
GD32F103C8T6 CAN没有输出
GD32F103C8T6 CAN没有输出 回环模式,可以读取回数据,但是我重映射的PB8,PB9没有信号出来,外接的TJA1050,请问有遇到类似问题的吗? 代码如下 can_trasnmit_message_struct transmit_message; can_receive_message_struct receive_message; uint8_t CAN_Tx_Buf[8]; uint8_t CAN_Rx_Buf[8]; /*! \brief initialize CAN and filter \param[in] can_parameter \arg can_parameter_struct \param[in] can_filter \arg can_filter_parameter_struct \param[out] none \retval none */ void BSP_CANInit(void) { can_parameter_struct can_parameter; can_filter_parameter_struct can_filter; /* configure CAN0 NVIC */ nvic_irq_enable(USBD_LP_CAN0_RX0_IRQn,1,2); /* enable CAN clock */ rcu_periph_clock_enable(RCU_CAN0); rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_AF); /* configure CAN0 GPIO */ gpio_pin_remap_config(GPIO_CAN_FULL_REMAP,ENABLE); gpio_init(GPIOB,GPIO_MODE_IPU,GPIO_OSPEED_50MHZ,GPIO_PIN_8); gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_9); /* initialize CAN and filter */ can_struct_para_init(CAN_INIT_STRUCT, &can_parameter); can_struct_para_init(CAN_FILTER_STRUCT, &can_filter); /* initialize CAN register */ can_deinit(CAN0); /* initialize CAN parameters */ can_parameter.time_triggered = DISABLE; //TTC 时间触发通信 0: 禁用时间触发通信 1: 使能时间触发通信 can_parameter.auto_bus_off_recovery = DISABLE; //ABOR 自动离线恢复 0: 通过软件手动地从离线状态恢复 1: 通过硬件自动的从离线状态恢复 can_parameter.auto_wake_up = DISABLE; //AWK 自动唤醒 0: 通过软件手动的从睡眠工作模式唤醒 1: 通过硬件自动的从睡眠工作模式唤醒 can_parameter.no_auto_retrans = ENABLE;//DISABLE; //ARD 自动重发禁止 0: 使能自动重发 1: 禁用自动重发 can_parameter.rec_fifo_overwrite = DISABLE; //RFOD 禁用接收FIFO满时覆盖 0: 使能接收FIFO满时覆盖 1: 禁用接收FIFO满时覆盖 can_parameter.trans_fifo_order = DISABLE; //TFO 发送FIFO顺序 0: 标识符(Identifier)较小的帧先发送 1: 所有等待发送的邮箱按照先进先出(FIFO)的顺序发送 #ifdef TEST_LOOPBACK can_parameter.working_mode = CAN_LOOPBACK_MODE; //回环模式 #else can_parameter.working_mode = CAN_NORMAL_MODE; //通信模式 #endif can_parameter.resync_jump_width = CAN_BT_SJW_1TQ; //SJW[1:0] 再同步补偿宽度 再同步补偿占用的时间单元数量= SJW[1:0]+1 can_parameter.time_segment_1 = CAN_BT_BS1_6TQ; //BS1[3:0] 位段1 位段1占用的时间单元数量=BS1[3:0]+1 can_parameter.time_segment_2 = CAN_BT_BS2_5TQ; //BS2[2:0] 位段2 位段2占用的时间单元数量=BS2[2:0]+1 can_parameter.prescaler = 6000 / CAN_BAUDRATE; //BRP[9:0] 波特率分频系数 /* initialize CAN */ can_init(CAN0, &can_parameter); /* CAN0 initialize filter */ can_filter.filter_number = 0; //disable filter // can_filter.filter_mode = CAN_FILTERMODE_LIST; //FMx 过滤器模式 0: 掩码模式 1: 列表模式 can_filter.filter_mode = CAN_FILTERMODE_MASK; //FMx 过滤器模式 0: 掩码模式 1: 列表模式 can_filter.filter_bits = CAN_FILTERBITS_32BIT; //FSx 过滤器位宽 0: 16-bit位宽 1: 32-bit位宽 can_filter.filter_list_high = FILTER_LIST_HIGH; //FDx 过滤器数据 can_filter.filter_list_low = FILTER_LIST_LOW; //FDx 过滤器数据 //列表模式下: //0: 标识符的Bit(x)必须为0 //1: 标识符的Bit(x)必须为1 can_filter.filter_mask_high = FILTER_MASK_HIGH; //FDx 过滤器数据 can_filter.filter_mask_low = FILTER_MASK_LOW; //FDx 过滤器数据 //掩码模式下: //0: 标识符的Bit(x)不需参与比较 //1: 标识符的Bit(x)需要参与比较 can_filter.filter_fifo_number = CAN_FIFO0; //FAFx 过滤器关联FIFO 0: 关联FIFO0 1: 关联FIFO1 can_filter.filter_enable = ENABLE; //FWx 过滤器激活 0: 没有激活 1: 激活工作 can_filter_init(&can_filter); /* enable can receive FIFO0 not empty interrupt */ can_interrupt_enable(CAN0, CAN_INTEN_RFNEIE0); } void CAN_process(void)//测试 1秒定时调用 { CAN_Tx_Buf[0] = 0x55; CAN_Tx_Buf[1] = 0xAA; CAN_Tx_Buf[2] = 0x01; CAN_Tx_Buf[3] = 0x02; CAN_Tx_Buf[4] = 0x03; CAN_Tx_Buf[5] = 0x04; CAN_Tx_Buf[6] = 0x05; CAN_Tx_Buf[7] = 0x06; BSP_CANWrite(CAN0, CAN_Tx_Buf); } void BSP_CANWrite(uint32_t can_periph, uint8_t *buff) { uint8_t i; #ifdef TEST_LOOPBACK uint32_t timeout = 0xFFFF; uint8_t transmit_mailbox = 0; #endif for (i = 0; i < 8; i++) { transmit_message.tx_data[i] = buff[i]; } /* initialize transmit message */ transmit_message.tx_sfid = TX_SFID; //SFID[10:0]/EFID[28:18] 标识符 //STID[10:0]: 标准格式帧标识符 //EXID[28:18]: 扩展格式帧标识符 transmit_message.tx_efid = TX_EFID; //EFID[17:0]: 扩展格式帧标识符 transmit_message.tx_ft = CAN_FT_DATA; //FT 帧种类 0: 数据帧 1: 遥控帧 // transmit_message.tx_ff = CAN_FF_STANDARD; //FF 帧格式 0: 标准格式帧 1: 扩展格式帧 transmit_message.tx_ff = CAN_FF_EXTENDED; //FF 帧格式 0: 标准格式帧 1: 扩展格式帧 transmit_message.tx_dlen = TX_DLEN; //DLC[3:0] 数据长度 #ifndef TEST_LOOPBACK /* transmit message */ can_message_transmit(can_periph, &transmit_message); #else /* transmit message */ transmit_mailbox = can_message_transmit(can_periph, &transmit_message); /* waiting for transmit completed */ while((CAN_TRANSMIT_OK != can_transmit_states(can_periph, transmit_mailbox)) && (0 != timeout)){ timeout--; } timeout = 0xFFFF; /* waiting for receive completed */ while((can_receive_message_length_get(can_periph, CAN_FIFO0) < (TX_DLEN - 1)) && (0 != timeout)){ timeout--; } /* initialize receive message*/ receive_message.rx_sfid = 0x00; receive_message.rx_ff = 0; receive_message.rx_dlen = 0; receive_message.rx_data[0] = 0x00; receive_message.rx_data[1] = 0x00; receive_message.rx_data[2] = 0x00; receive_message.rx_data[3] = 0x00; receive_message.rx_data[4] = 0x00; receive_message.rx_data[5] = 0x00; receive_message.rx_data[6] = 0x00; receive_message.rx_data[7] = 0x00; can_message_receive(CAN0, CAN_FIFO0, &receive_message); for(i = 0; i < TX_DLEN; i++) { System.com.can_rx[i] = receive_message.rx_data[i]; } CAN_TO_USART(COM_RS422); #endif } /*! \brief this function handles CAN0 RX0 exception \param[in] none \param[out] none \retval none */ void CAN0_RX0_IRQHandler(void) { uint8_t i; gd_eval_led_toggle(); /* check the receive message */ can_message_receive(CAN0, CAN_FIFO0, &receive_message); // if((TX_SFID == receive_message.rx_sfid) && (CAN_FF_STANDARD == receive_message.rx_ff) && (TX_DLEN == receive_message.rx_dlen)) if((TX_EFID == receive_message.rx_efid) && (CAN_FF_EXTENDED == receive_message.rx_ff) && (TX_DLEN == receive_message.rx_dlen)) { for(i = 0; i < TX_DLEN; i++) { System.com.can_rx[i] = receive_message.rx_data[i]; } CAN_TO_USART(COM_RS422); }else{ } }
4175浏览量 1回复量 关注量