我能';在CAN_TX线路上看不到任何信号

我能';在CAN_TX线路上看不到任何信号,c,stm32,can-bus,C,Stm32,Can Bus,我尝试在STM32F303发现板上使用CAN总线,我正在使用PD0→RX和PD1→TX引脚 我想尝试在示波器上发送信息并进行分析。因此,我的配置见下面的代码块 当我用示波器分析哪些引脚是PD0和PD1时,我在示波器上看不到任何东西 我的错在哪里 这是我的代码: #include <stm32f30x.h> #include <stm32f30x_i2c.h> #include <stm32f30x_rcc.h> #include <stm32f30x_s

我尝试在STM32F303发现板上使用CAN总线,我正在使用PD0→RX和PD1→TX引脚

我想尝试在示波器上发送信息并进行分析。因此,我的配置见下面的代码块

当我用示波器分析哪些引脚是PD0和PD1时,我在示波器上看不到任何东西

我的错在哪里

这是我的代码:

#include <stm32f30x.h>
#include <stm32f30x_i2c.h>
#include <stm32f30x_rcc.h>
#include <stm32f30x_syscfg.h>
#include <stm32f30x_exti.h>
// #include <stm32f30x_misc.h>
#include "main.h"
#include <stdio.h>
#include "common.h"
#include "io_periph_defs.h"
#include "stm32f30x.h"
#include <stdio.h>
#include "conf.h"

GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CanTxMsg TxMessage;
CanRxMsg RxMessage;

void Init_TxMes(CanTxMsg *TxMessage)
{
    /* Transmit INITIALIZATION*/

    TxMessage->IDE = CAN_ID_STD;

    TxMessage->DLC = 2;

    TxMessage->StdId = 0x321;

    TxMessage->RTR = CAN_RTR_DATA;
}

void Init_RxMes(CanRxMsg *RxMessage)
{
    uint8_t i = 0;

    RxMessage->StdId = 0;

    RxMessage->IDE = CAN_ID_STD;

    RxMessage->DLC = 0;

    RxMessage->FMI = 0;

    for (i = 0; i < 8; i++)
    {
        RxMessage->Data[i] = 0;
    }
}

void CAN_setup(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); //Enable the clock for CAN

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);

    /* Configure CAN1 RX pin */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_Init(GPIOD, &GPIO_InitStructure);

    /* Configure CAN1 TX pin */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOD, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_9);

    GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_9);
    /* Enable the CAN global Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = CAN1_SCE_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX1_IRQn;

    NVIC_Init(&NVIC_InitStructure);

    CAN_DeInit(CAN1);

    /* Configure CAN1 **************************************************/

    /* Struct init*/

    CAN_StructInit(&CAN_InitStructure);

    /* CAN cell init */
    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 Baudrate = 125kbps (CAN clocked at 36 MHz) */
    CAN_InitStructure.CAN_BS1 = CAN_BS1_9tq;
    CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
    CAN_InitStructure.CAN_Prescaler = 16;
    CAN_Init(CAN1, &CAN_InitStructure);

    /* CAN filter init */
    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 = 0;

    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
    CAN_FilterInit(&CAN_FilterInitStructure);
}

int main(void)
{
    int i;

    uint8_t TransmitMailbox = 0;

    CAN_setup(); // Set up CAN interface

    Init_TxMes(&TxMessage);
    init_pin(GPIOA, GPIO_Pin_8, GPIO_Mode_OUT, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_UP);

    while (1)
    {
        TxMessage.Data[0] = 0xAA;
        GPIO_SetBits(GPIOA, GPIO_Pin_8); // Transmit data

        TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);

        i = 0;
        while ((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK))
            ;                              // I put a breakpoint here to check
                                           // and found the message is pending.

        GPIO_ResetBits(GPIOA, GPIO_Pin_8); // Transmit data

        //i++;
    }
}

这看起来你忘记了120欧姆的电阻。我可以把120欧姆的电阻放在哪里。我只使用STM32和计算机。我应该把它放在rx和tx引脚之间吗?是的。你可以把60欧姆,而不是两个120欧姆仅仅用于测试。这个问题是。这看起来你忘记了120欧姆的电阻器。我可以把120欧姆的电阻放在哪里。我只使用STM32和计算机。我应该把rx和tx引脚之间的电阻放在哪里?是的。你可以用60欧姆代替两个120欧姆来测试。这个问题正在讨论中。
while ((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK)