Home > other >  The CAN communication abnormal use is SN65HVD230DRG4 chip
The CAN communication abnormal use is SN65HVD230DRG4 chip

Time:09-21

What a great god help to take a look at the CAN communication exists abnormal, chip USES is SN65HVD230DRG4 (use TJA1050 CAN normal send and receive data, use SN65HVD230DRG4 CAN't send and receive data, through a resistor RS pin to the low level), the following code, which a great god, please help some directions
# include "is the main. H"
Unsigned char can1_rec_flag=0;
Unsigned char CAN1_DATA [8].
Unsigned char can2_rec_flag=0;
Unsigned char CAN2_DATA [8].
//format: baud rate CAN_SJW CAN_BS1 CAN_BS2 CAN_Prescaler
Const unsigned int CAN_baud_table [CAN_BAUD_NUM] [5]=
{
//the baud rate, CAN_SJW CAN_BS1, CAN_BS2, CAN_Prescaler
{5, CAN_SJW_1tq, CAN_BS1_13tq, CAN_BS2_2tq, 450},//not through
{10, CAN_SJW_1tq, CAN_BS1_6tq, CAN_BS2_2tq, 400},//not through
{15, CAN_SJW_1tq, CAN_BS1_13tq, CAN_BS2_2tq, 150},//15 k
{20, CAN_SJW_1tq, CAN_BS1_6tq, CAN_BS2_2tq, 200},//20 k
{25, CAN_SJW_1tq, CAN_BS1_13tq, CAN_BS2_2tq, 90},//25 k
{40, CAN_SJW_1tq, CAN_BS1_6tq, CAN_BS2_2tq, 100},//40 k
{50, CAN_SJW_1tq, CAN_BS1_13tq CAN_BS2_2tq, 45},//50 k
{62, CAN_SJW_1tq CAN_BS1_13tq, CAN_BS2_2tq, 36},//62.5 k
{80, CAN_SJW_1tq CAN_BS1_6tq, CAN_BS2_2tq, 50},//80 k
{100, CAN_SJW_1tq CAN_BS1_5tq, CAN_BS2_2tq, 45},//100 k
{125, CAN_SJW_1tq CAN_BS1_13tq CAN_BS2_2tq, 18},//125 k
{200, CAN_SJW_1tq CAN_BS1_6tq, CAN_BS2_2tq, 20},//200 k
{250, CAN_SJW_1tq CAN_BS1_13tq, CAN_BS2_2tq, 9},//250 k
{400, CAN_SJW_1tq CAN_BS1_6tq, CAN_BS2_2tq, 10},//400 k
{500, CAN_SJW_1tq CAN_BS1_5tq, CAN_BS2_2tq, 9},//500 k
{666, CAN_SJW_1tq CAN_BS1_5tq, CAN_BS2_2tq, 8},//not through
{800, CAN_SJW_1tq CAN_BS1_6tq, CAN_BS2_2tq, 5},//800 k
{1000, CAN_SJW_1tq CAN_BS1_6tq, CAN_BS2_2tq, 4},//1000 k
};
Void CAN_GPIO_Configuration (void)
{
GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);//can make PORTA clock


//GPIO_PinRemapConfig (GPIO_Remap2_CAN1, ENABLE);//multiplexing pins setting
//GPIO_PinRemapConfig (GPIO_Remap_CAN2, ENABLE);

RCC_APB1PeriphClockCmd (RCC_APB1Periph_CAN1, ENABLE);//can make CAN1 clock
RCC_APB1PeriphClockCmd (RCC_APB1Periph_CAN2, ENABLE);//can make CAN2 clock


/* Configure CAN1 pin: RX - & gt; PA11 pull-up type */
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

/* Configure CAN1 pin: TX - & gt; Push-pull */PA12 reuse
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

/* Configure CAN1 pin: RS - & gt; PA15 reuse push-pull */
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

/* Configure CAN2 pin: RX */
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init (GPIOB, & amp; GPIO_InitStructure);
/* Configure CAN2 pin: TX */
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init (GPIOB, & amp; GPIO_InitStructure);

RS_OFF;
}


Void CAN_Configuration (void)
{

CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;

CAN_DeInit (CAN1);
CAN_DeInit (CAN2);
CAN_StructInit (& amp; CAN_InitStructure);

/* CAN cell init */
CAN_InitStructure. CAN_TTCM=DISABLE;/* time trigger, trigger: CAN the hardware of the internal timer is activated, and is used to produce a timestamp */
CAN_InitStructure. CAN_ABOM=DISABLE;/* off-line ban, automatic offline: once the hardware monitoring to 128 11 recessive, automatically quit offline, software to set to quit here */
CAN_InitStructure. CAN_AWUM=DISABLE;/* automatically wake up with a message from to automatically quit when sleep */
CAN_InitStructure. CAN_NART=ENABLE;/* packet retransmission, if the error has been uploaded successfully, otherwise only preach a */
CAN_InitStructure. CAN_RFLM=DISABLE;/* receive FIFO lock, 1 - lock after receiving new abstract don't, 0 - the previous message received a new message is covered */
CAN_InitStructure. CAN_TXFP=ENABLE;/* send priority 0 - determined by 1 - identifier is determined by the request order */
CAN_InitStructure. CAN_Mode=CAN_Mode_Normal;/* mode */


CAN_Baud_Process (250, & amp; CAN_InitStructure);//baud rate 250 k
//CAN_Init (CAN1, & amp; CAN_InitStructure);
//CAN_Init (CAN2, & amp; CAN_InitStructure);
If (CAN_Init (CAN1, & amp; CAN_InitStructure)==CANINITFAILED)
{

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related