memcpy(ARPBUF->
memcpy(ARPBUF->
ARPBUF->
ARPBUF->
ARPBUF->
ARPBUF->
ARPBUF->
memcpy(ARPBUF->
memcpy(ARPBUF->
memcpy(ARPBUF->
switch ( HON( ARPBUF->
break;
case 1://10K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 225;
break;
case 2: //50K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 45;
break;
case 3: //100K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_14tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 20;
break;
case 4://125K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 18;
break;
case 5: //250K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 9;
break;
case 6://500K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 9;
break;
case 7: //1M
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_8tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 3;
break;
default://125K
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_13tq;//CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;//CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 18;
break;
}
}
CAN_Init(CAN1, &CAN_InitStructure);
}
void CAN_SetAddr(uint8_t addr)
{
uint32_t address;
//uint32_t addrmask;
address=addr;
address=address<(13+3);
//addrmask=(0xff<(13+3));
CAN_FilterInitStructure.CAN_FilterNumber=0;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = (((u32)address)&0xFFFF0000)>>16;
CAN_FilterInitStructure.CAN_FilterIdLow = (((u32)address)|CAN_ID_EXT|CAN_RTR_DATA)&0xFFFF;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x00ff;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x05;
//CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0;
//CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0;
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
}
void CAN_InitEx(uint8_t addr,uint8_t uBaud)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |RCC_APB2Periph_GPIO_CAN1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
#ifndef AMP12_CAN
GPIO_PinRemapConfig(GPIO_Remap1_CAN1 , ENABLE);
#endif
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_CAN, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_TX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;