这是我的CAN传输程序。我只想看透 示波器是否发送了某些东西。我正在使用stm32f407 和真正的工作室,但我看不到任何信号 TX针。请告诉我我的错误在哪里。我是否需要在外部连接收发器以及如何访问CAN_H和CAN_L引脚。
#include "stm32f4xx.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_ClocksTypeDef RCC_Clocks;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CanTxMsg TxMessage;
RCC_GetClocksFreq(&RCC_Clocks);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);`
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
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(GPIOD, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(CAN1, &CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
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 = CAN_FIFO0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
// transmit */
TxMessage.StdId= 0x123;
TxMessage.ExtId= 0x00;
TxMessage.RTR= CAN_RTR_DATA;
TxMessage.IDE= CAN_ID_STD;
TxMessage.DLC= 4;
TxMessage.Data[0]= 0x02;
TxMessage.Data[1]= 0x11;
TxMessage.Data[2]=0x11;
TxMessage.Data[3]=0x11;
while(1)
{
volatile uint_t i;
unit8_t TransmitMailbox= 0;
//sprintf(TxMessage.Data, "Imran\n");
TransmitMailbox= CAN_Transmit(CAN1,&TxMessage);
i=0;
while((CAN_TransmitStatus(CAN1,TransmitMailbox) !=CANTXOK)&& (i !=0xFFFFFF))
{
i++;
}
}
}
答案 0 :(得分:1)
尝试通过更改以下行来打开“自动唤醒”:
CAN_InitStructure.CAN_AWUM = ENABLE;
stm32f407仅具有CAN控制器,而没有内部收发器,因此您需要将其外部连接。另外,您还必须将另一台设备连接到CAN总线上才能看到内容(记住有关终结器的信息)。
请通过以下方式解释您的意思:
how can i access CAN_H and CAN_L pins
PS。您不应将每种功能都放在一个例程中,因为它不可读。