#include "gd32f10x.h"
#include "systick.h"
#include <stdio.h>
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
void Delay(unsigned long i)
{
while(i--) ;
}
can_trasnmit_message_struct transmit_message;
can_receive_message_struct receive_message;
uint16_t receive_flag=0;
void CAN0_RX1_IRQHandler(void)
{
/* check the receive message */
can_message_receive(CAN0, CAN_FIFO1, &receive_message);
gpio_bit_write(GPIOC, GPIO_PIN_1,(bit_status)(1-gpio_input_bit_get(GPIOC, GPIO_PIN_1)));
//gpio_bit_write(GPIOC, GPIO_PIN_13,(bit_status)(1-gpio_input_bit_get(GPIOC, GPIO_PIN_13)));
if((0x321 == receive_message.rx_sfid)&&(CAN_FF_STANDARD == receive_message.rx_ff) && (2 == receive_message.rx_dlen)){
receive_flag = SET;
}
}
void can_config(void)
{
can_parameter_struct can_parameter;
can_filter_parameter_struct can_filter;
/* initialize CAN register */
can_deinit(CAN0);
/* initialize CAN parameters */
can_parameter.time_triggered = DISABLE;
can_parameter.auto_bus_off_recovery = DISABLE;
can_parameter.auto_wake_up = DISABLE;
can_parameter.no_auto_retrans = ENABLE;
can_parameter.rec_fifo_overwrite = DISABLE;
can_parameter.trans_fifo_order = DISABLE;
can_parameter.working_mode = CAN_NORMAL_MODE;
can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
can_parameter.time_segment_1 = CAN_BT_BS1_3TQ;
can_parameter.time_segment_2 = CAN_BT_BS2_2TQ;
can_parameter.prescaler = 80; //72M / 120 / (2+3+1) = 10000kbps
can_init(CAN0, &can_parameter);
/* initialize filter */
can_filter.filter_number=0;
can_filter.filter_mode = CAN_FILTERMODE_MASK;
can_filter.filter_bits = CAN_FILTERBITS_32BIT;
can_filter.filter_list_high = 0x0020;
can_filter.filter_list_low = 0x0000;
can_filter.filter_mask_high = 0x0000;
can_filter.filter_mask_low = 0x0000;
can_filter.filter_fifo_number = CAN_FIFO1;
can_filter.filter_enable = ENABLE;
can_filter_init(&can_filter);
nvic_irq_enable(CAN0_RX1_IRQn, 0, 0);
can_interrupt_enable(CAN0, CAN_INTEN_RFNEIE1);
}
uint32_t timeout = 0xFFFF;
uint8_t transmit_mailbox = 0;
can_transmit_state_enum state=0;
int main(void)
{
Delay(2000000);
systick_config();
rcu_periph_clock_enable(RCU_GPIOC);
gpio_init(GPIOC, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
rcu_periph_clock_enable(RCU_CAN0);
rcu_periph_clock_enable(RCU_GPIOB);
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
gpio_init(GPIOB, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_8); //PB12 -- CAN1_RX
gpio_pin_remap_config(GPIO_CAN_FULL_REMAP,ENABLE);
can_config();
transmit_message.tx_sfid = 0x0002; //standard format frame identifier
transmit_message.tx_efid = 0x00; //extended format frame identifier
transmit_message.tx_ft = CAN_FT_DATA; //type of frame, data or remote
transmit_message.tx_ff = CAN_FF_STANDARD; //format of frame, standard or extended format
transmit_message.tx_dlen = 2; //data length
transmit_message.tx_data[0] = 0x11;
transmit_message.tx_data[1] = 0x22;
while(1)
{
transmit_mailbox=can_message_transmit(CAN0, &transmit_message);
timeout = can_transmit_states(CAN0, transmit_mailbox);
//gpio_bit_write(GPIOC, GPIO_PIN_1,(bit_status)(1-gpio_input_bit_get(GPIOC, GPIO_PIN_1)));
Delay(2000000);
}
return 0;
} |
@天月 :没解决,后来用STM32,程序还是那段程序,都是好的,-43°也没问题
解决了吗,是什么情况啊