STM32F205ZET6单片机,使用PA11和PA12进行CAN通信,收发器无论是ISO1050还是TJA1050,都不成功,发送信息时,CAN_TransmitStatus函数一直返回Pending,请问是为什么啊?
另外,使用CAN分析仪——收发器——PA11,PA12连接时,单片机的PA11和PA12引脚是有波形的,,两个引脚都有方波,TXD上的波形密集些,RXD上面的好像只有一个低脉冲,占空比很高,
主要是使用ISO1050芯片通讯,但是就无法发送数据,也没有办法进入到接收终端之中,中断函数我自认为配置好了,和库函数的配置是一样的,
ISO1050 电路为:有120欧终端电阻,CAN_TX和CAN_RX接上拉电阻472,CANH和CANL之间有120欧终端电阻,并且各串接了一个零欧电阻,
大家交流交流?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
- int main(void)
- {
- RCC_ClocksTypeDef RCC_Clocks;
- //&**** SysTick end of count event each 10ms *****&/
- RCC_GetClocksFreq(&RCC_Clocks);
- SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
- NVIC_Config();
- LED_Config();
- CAN_Config();
- while(1)
- {
- CAN_Trans();
- Delay(60);
- }
- }
- void NVIC_Config(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel=CAN1_RX0_IRQn; //中断请求 CAN1_RX0_IRQn
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- void CAN_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- /* Connect CAN pins to AF9 */
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
- /* Configure CAN RX and TX pins */
- /* PA11 RX-上拉输入,PA12 TX-复用推挽输出*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // 推挽输出
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉输入
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
-
- CAN_DeInit(CAN1);
- CAN_InitStructure.CAN_TTCM = DISABLE; //time triggered communication mode
- CAN_InitStructure.CAN_ABOM = DISABLE; //automatic bus-off management
- CAN_InitStructure.CAN_AWUM = DISABLE; //automatic wake-up mode
- CAN_InitStructure.CAN_NART = DISABLE; //non-automatic retransmission mode
- CAN_InitStructure.CAN_RFLM = DISABLE; //Receive FIFO Locked mode
- CAN_InitStructure.CAN_TXFP = DISABLE; //transmit FIFO priority
- CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
-
- /*主板的时钟使用外部告诉时钟,25MHz,CAN clocked(APB1) at 30 MHz, set CAN Baudrate = 125KBps
- than, how to calculate the Tq*/
- /* 主板的时钟使用外部高速时钟,25MHz Baudrate = 500 Kbps ,CAN clocked (APB1) at 30MHz*/
- CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; //Specifies the maximum number of time quanta
- CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
- CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
- CAN_InitStructure.CAN_Prescaler = 4; //30 000000/(1+6+8)/4= 30 000000/(1+2+3)/10=
- CAN_Init(CAN1, &CAN_InitStructure);
- CAN_FilterInitStructure.CAN_FilterNumber = 0;
- CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;// CAN_FilterMode_IdList
- CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
- CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
- CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
- CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
- CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
- CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; //FIFO0
- CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
- CAN_FilterInit(&CAN_FilterInitStructure);
-
-
- TxMessage.StdId = 0x04; //standard ID
- TxMessage.ExtId = 0x00; //extend ID
- TxMessage.RTR = CAN_RTR_DATA; //data frame
- TxMessage.IDE = CAN_ID_STD; //standard ID
- TxMessage.DLC = 1; //length of data
- TxMessage.Data[0] = 0xDE;
-
- CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); // finish sending Interrupt CAN_IT_TME, Enable FIFO 0 message pending Interrupt
-
- }
- void CAN_Trans(void)
- {
- uint32_t i=0;
- uint8_t TransmitMailbox=0;
- /* Transmit Structure preparation */
- TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
- //CAN_Transmit(CAN1, &TxMessage);
- i = 0;
- //一定时间内不断发送,直到:1、发送成功==CANTXOK,2、i !=0xFFFF
- while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK ) && (i != 0xFFFF)) // CAN_TxStatus_Failed
- {
- i++; //发送失败
- }
- i = 0;
- while((CAN_MessagePending(CAN1, CAN_FIFO0) <1 ) && (i != 0xFFFF))
- {
- i++; //MessagePending 不是FIFO 1,也不是FIFO 0
- }
- }
复制代码你这样说让我有点想骂人。。。。。,我之前就让你排除硬件问题,你告诉我的硬件没有问题。。。。。。。
我们这种控制,硬件是软件的基础,硬件都有问题,你的软件写的再牛逼,也没有用。。。。
一周热门 更多>