-1

我正在开发一个使用 PIC18F47Q83 对 CAN 总线进行读/写的项目,但我们无法从收发器写入任何数据我们的代码基于 microchip 在此地址提供的项目发现:https://mplab -discover.microchip.com/v1/item/com.microchip.ide.project/com.microchip.subcategories.modules-and-peripherals.communication.can-fd/com.microchip.mcu8.mplabx.project.pic18f47q84-can -fd-basic-operation/1.0.0?view=about&s0=com.microchip.ide.project%3Aperipherals%3ACAN&ds0=com.microchip.portal.start.displayCharacteristics%3A1.1.0%3As0

我们已经完成了从 PIC18f47Q84 到 PIC18F47Q83 以及从 CAN FD 到 CAN 的更改。我们的硬件由以下组成:

  • PIC18F47Q83
  • CAN 收发器(ATA6563 点击)。
  • Curiosity HPC(高引脚数)开发板
  • 8MHz 石英

我们正在开发 Mplab X v6.0 和 MCC v2.3 我们的代码如下:

void TMR0_DefaultInterruptHandler(void){
    LED_PIN_SetHigh();
    CAN_MSG_OBJ Transmission;  //create the CAN message object
    uint8_t Transmit_Data[8]={0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77}; // data bytes
    
    if(CAN_OP_MODE_REQUEST_SUCCESS == CAN1_OperationModeSet(CAN_NORMAL_2_0_MODE))
    {
        Transmission.field.brs=CAN_NON_BRS_MODE; //Transmit the data bytes at data bit rate
        Transmission.field.dlc=DLC_8; //8 data bytes
        //Transmission.field.formatType=CAN_FD_FORMAT; //CAN FD frames 
        Transmission.field.formatType=CAN_2_0_FORMAT;
        Transmission.field.frameType=CAN_FRAME_DATA; //Data frame
        Transmission.field.idType=CAN_FRAME_STD; //Standard ID
        Transmission.msgId=0x2b8c; //ID of 0x100
        Transmission.data=Transmit_Data; //transmit the data from the data bytes
        
        if(CAN_TX_FIFO_AVAILABLE == (CAN1_TransmitFIFOStatusGet(TXQ) & CAN_TX_FIFO_AVAILABLE))//ensure that the TXQ has space for a message
        {
            CAN1_Transmit(TXQ, &Transmission); //transmit frame
        }
    }
    LED_PIN_SetLow();
}

下面是 CAN_MSG_OBJ 的定义:

typedef union 
{
    uint8_t msgfields;
    struct
    {
        uint8_t idType:1;       // 1 bit (Standard Frame or Extended Frame)
        uint8_t frameType:1;    // 1 bit (Data Frame or RTR Frame)
        uint8_t dlc:4;          // 4 bit (No of data bytes a message frame contains)
        uint8_t formatType:1;   // 1 bit (CAN 2.0 Format or CAN_FD Format)
        uint8_t brs:1;          // 1 bit (Bit Rate Switch)
    };
} CAN_MSG_FIELD;

typedef struct 
{
    uint32_t msgId;          // 29 bit (SID: 11bit, EID:18bit)
    CAN_MSG_FIELD field;     // CAN TX/RX Message Object Control
    uint8_t *data;           // Pointer to message data
} CAN_MSG_OBJ;   

当代码在 TMR0 处理中时,LED 会闪烁,但 CANTx 和 CANRx 引脚上没有任何显示。

提前感谢您的时间和答案。

4

0 回答 0