main_ex3.c

来自「canbus分析仪使用说明,很用用的,快来看吧」· C语言 代码 · 共 81 行

C
81
字号
/*C**************************************************************************
* Main_ex3.c 
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
* PURPOSE: 
* The goal of this exercice is to learn How to use the CAN_lib to initialize
* a CAN channel (Message object) in reception.
* 
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h"
#include "compiler.h"
#include "can_lib.h"

/* Starter Kit configuration */
/*#define BRP_100k    0x05
#define SJW_100k    0x00
#define PRS_100k    0x01
#define PHS2_100k   0x03
#define PHS1_100k   0x02

/* PHYTEC configuration */
#define BRP_100k 0x09
#define SJW_100k 0x00
#define PRS_100k 0x03
#define PHS2_100k 0x02
#define PHS1_100k 0x01

can_data_t data_temp;
can_msg_t can_temp;
void main(void)
{

  
/*________________________________________*/
/*_____ CAN CONTROLLER CONFIGURATION _____*/
/*________________________________________*/

  CAN_CONTROLLER_RESET; 
  RazAllMailbox();
  CanSetBRP  (BRP_100k);
  CanSetSJW  (SJW_100k);
  CanSetPRS  (PRS_100k);
  CanSetPHS2 (PHS2_100k);
  CanSetPHS1 (PHS1_100k);
  CAN_CONTROLLER_ENABLE;

  pt_st_can_rx = &can_temp;
  can_temp.pt_donne = data_temp;
/*_______________________________________________________________*/
/*_____ CONFIGURE THE MESSAGE OBJECT 0 TO RECEIVE A MESSAGE _____*/
/*_______________________________________________________________*/
  CAN_SET_CHANNEL(CHANNEL_0);
  can_rx_filt.std = 0x123;
  can_rx_msk.std  = 0x7FF;
  conf_rx = CONF_NOBUFFER;
  ConfChannel_Rx();

  while((CANSTCH&MSK_CANSTCH_Rx_OK)!= MSK_CANSTCH_Rx_OK);

  ReadCanMsg(CHANNEL_DISABLE);

 /*____________________________________________________________*/
/*_____ CONFIGURE THE MESSAGE OBJECT 1 TO SEND A MESSAGE _____*/
/*____________________________________________________________*/
  CAN_SET_CHANNEL(CHANNEL_1);
  can_tx_id     = pt_st_can_rx->id;
  conf_tx       = (pt_st_can_rx->ctrl & 0x08); 
  pt_candata_tx = pt_st_can_rx->pt_donne;

  SendCanMsg();


  while(1);
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?