如题,工程是从GD32103C-EVAL开发板的CAN工程移植而来,因为开发板用的是GD32F103VCT6,CAN0的引脚是PD0和PD1,且需要重映射,而GD32F103C8T6的CAN0引脚是PA11和PA12,且不需要重映射,所以修改的地方基本就两个,一是将重映射取消,二是将PIN脚修改成C对应的引脚,但是下载之后TX维持在1.3V,RX维持在1.9V,即时将中断代码注释,仅留下发送代码也是如此,但是只要不执行发送,管脚的电平就是正常的,一旦执行发送就会电平异常。望有经验的同学指点一二,C8T6代码如下:
//main.c
void RCC_Configuration(void);
void NVIC_Configuration(void);
void RCC_Configuration(void)
{
RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA , ENABLE);
// RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB , ENABLE);
// RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC , ENABLE);
// RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOD , ENABLE);
// RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOE , ENABLE);
// RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_AF , ENABLE);
// RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE);
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_CAN1, ENABLE);
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Configure the nested vectored interrupt controller.
* @param None
* @retval None
*/
void NVIC_Configuration(void)
{
NVIC_InitPara NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_VectTableSet(NVIC_VECTTAB_FLASH, 0x0);
#endif
NVIC_PRIGroup_Enable(NVIC_PRIGROUP_1);
NVIC_InitStructure.NVIC_IRQ = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;
NVIC_InitStructure.NVIC_IRQSubPriority = 0x0;
NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
int main(void)
{
// RCC_Configuration();
// NVIC_Configuration();
SysTick_Configuration();
CAN_GPIO_Configuration();
CAN_Configuration();
// CAN_INTConfig(CAN1, CAN_INT_RFNE0, ENABLE);
while(1) {
TxMessage.Data[0] = 0x55;
CAN_Transmit(CAN1, &TxMessage);
}
}
//
//can.c
void CAN_GPIO_Configuration(void)
{
GPIO_InitPara GPIO_InitStructure;
RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA , ENABLE);
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_CAN1, ENABLE);
/* Remap CAN GPIOs */
//GPIO_PinRemapConfig(GPIO_REMAP2_CAN1 , ENABLE);
/* Configure CAN TX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure CAN RX pin */
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_11;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/**
* @brief Configures the CAN.
* @param None
* @retval None
*/
void CAN_Configuration(void)
{
CAN_InitPara CAN_InitStructure;
CAN_FilterInitPara CAN_FilterInitStructure;
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTC = DISABLE;
CAN_InitStructure.CAN_ABOR = DISABLE;
CAN_InitStructure.CAN_AWK = DISABLE;
CAN_InitStructure.CAN_ARD = DISABLE;
CAN_InitStructure.CAN_RFOD = DISABLE;
CAN_InitStructure.CAN_TFO = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_MODE_NORMAL;
CAN_InitStructure.CAN_SJW = CAN_SJW_1TQ;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3TQ;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5TQ;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FILTERMODE_MASK;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FILTERSCALE_32BIT;
CAN_FilterInitStructure.CAN_FilterListHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterListLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskListHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskListLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssociation = 0;
CAN_FilterInitStructure.CAN_FilterWork = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* Transmit */
TxMessage.StdId = 0x602;
TxMessage.ExtId = 0x00;
TxMessage.FT = CAN_FT_DATA;
TxMessage.FF = CAN_FF_STANDARD;
TxMessage.DLC = 8;
}
|