本文整理匯總了C++中CAN_DeInit函數的典型用法代碼示例。如果您正苦於以下問題:C++ CAN_DeInit函數的具體用法?C++ CAN_DeInit怎麽用?C++ CAN_DeInit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CAN_DeInit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: cpu_deinit_all
void cpu_deinit_all() {
//** ADC_DeInit(LPC_ADC);
CAN_DeInit(LPC_CAN1);
CAN_DeInit(LPC_CAN2);
EMAC_DeInit();
EXTI_DeInit();
I2C_DeInit(LPC_I2C0);
I2C_DeInit(LPC_I2C1);
I2C_DeInit(LPC_I2C2);
I2S_DeInit(LPC_I2S);
NVIC_DeInit();
NVIC_SCBDeInit();
PWM_DeInit(LPC_PWM1);
QEI_DeInit(LPC_QEI);
//** RIT_DeInit(LPC_RIT);
RTC_DeInit(LPC_RTC);
SPI_DeInit(LPC_SPI);
SSP_DeInit(LPC_SSP0);
SSP_DeInit(LPC_SSP1);
UART_DeInit(LPC_UART0);
UART_DeInit((LPC_UART_TypeDef *) LPC_UART1);
//** UART_DeInit(LPC_UART2);
//** UART_DeInit(LPC_UART3);
TIM_DeInit(LPC_TIM0);
TIM_DeInit(LPC_TIM1);
//** TIM_DeInit(LPC_TIM2);
//** TIM_DeInit(LPC_TIM3);
}
示例2: CAN_CAN_Config
void CAN_CAN_Config(void)
{
CAN_InitTypeDef CAN_InitStructure;
/* Enable CAN clock */
#if USE_CAN1_R0 || USE_CAN1_R1
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1 , ENABLE);
CAN_DeInit(CAN1);
#endif
#if USE_CAN2_R0 || USE_CAN2_R1
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2 , ENABLE);
CAN_DeInit(CAN2);
#endif
/* 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;//失能接收FIFO鎖定模式,即FIFO溢出時新數據覆蓋
CAN_InitStructure.CAN_TXFP = ENABLE; //使能發送FIFO優先級,報文順序由發送順序決定 DISABLE:ID決定
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_2tq; //BTR-SJW 重新同步跳躍寬度 1個時間單元
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq; //BTR-TS1 時間段1 占用了2個時間單元
CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq; //BTR-TS1 時間段2 占用了3個時間單元
//總線波特率,波特率計算請參見 F4手冊“24.7.7 Bit timing”
#if CAN1_BAUDRATE == 1000 /* 1MBps */
CAN_InitStructure.CAN_Prescaler =6; //BTR-BRP 波特率分頻器 定義了時間單元的時間長度 42/(1+3+3)/6=1Mbps
#elif CAN1_BAUDRATE == 500 /* 500KBps */
CAN_InitStructure.CAN_Prescaler =12;
#elif CAN1_BAUDRATE == 250 /* 250KBps */
CAN_InitStructure.CAN_Prescaler =24;
#elif CAN1_BAUDRATE == 125 /* 125KBps */
CAN_InitStructure.CAN_Prescaler =48;
#endif
#if USE_CAN1_R0 || USE_CAN1_R1
CAN_Init(CAN1, &CAN_InitStructure);
#endif
#if USE_CAN2_R0 || USE_CAN2_R1
CAN_Init(CAN2, &CAN_InitStructure);
#endif
}
示例3: CAN_config_init
void CAN_config_init(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
// 36M 250k速率
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=ENABLE;
//CAN_InitStructure.CAN_Mode=CAN_Mode_LoopBack;
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_2tq;
CAN_InitStructure.CAN_BS2=CAN_BS2_3tq;
CAN_InitStructure.CAN_Prescaler=12;
CAN_Init(CAN1, &CAN_InitStructure);
CAN_OperatingModeRequest( CAN1, CAN_OperatingMode_Normal);
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);
}
示例4: platform_can_setup
u32 platform_can_setup( unsigned id, u32 clock )
{
LPC_CAN_TypeDef * canx;
uint32_t div;
switch (id)
{
case 0: canx = LPC_CAN1; break;
case 1: canx = LPC_CAN2; break;
default: return 0;
}
CAN_DeInit(canx);
CAN_Init(canx, clock);
CAN_ModeConfig(canx, CAN_OPERATING_MODE, ENABLE);
CAN_IRQCmd(canx, CANINT_RIE, ENABLE); // Receive IRQ
CAN_IRQCmd(canx, CANINT_EIE, ENABLE); // Error IRQ
CAN_IRQCmd(canx, CANINT_BEIE, ENABLE); // Bus error IRQ
LPC_CANAF->AFMR = 2; // Filter bypass (receive all messages)
NVIC_EnableIRQ(CAN_IRQn); // Enable IRQs
// Fix clock
LPC_SC->PCLKSEL0 &= ~(3<<26 | 3<<28 | 3<<30); // PCLK / 2
LPC_SC->PCLKSEL0 |= (2<<26 | 2<<28 | 2<<30);
div = (SystemCoreClock / 20) / clock;
div --;
canx->MOD = 0x01; // Enter reset mode
canx->BTR = (div & 0x3FF) | (3<<14) | (5<<16) | (2<<20) ; // Set bit timing
canx->MOD = 0; // Return to normal operating
// Change pin function (for now using the MBED ones)
// And read clock divider
if (id == 0)
{
// Pin function
LPC_PINCON->PINSEL0 &= ~(3<<0 | 3<<2);
LPC_PINCON->PINSEL0 |= (1<<0 | 1<<2);
// No pull up / pull down
LPC_PINCON->PINMODE0 &= ~(3<<0 | 3<<2);
LPC_PINCON->PINMODE0 |= (2<<0 | 2<<2);
// NOT open drain
LPC_PINCON->PINMODE_OD0 &= ~(1<<0 | 1<<1);
}
else
{
LPC_PINCON->PINSEL0 &= ~(3<<8 | 3<<10);
LPC_PINCON->PINSEL0 |= (2<<8 | 2<<10);
// No pull up / pull down
LPC_PINCON->PINMODE0 &= ~(3<<8 | 3<<10);
LPC_PINCON->PINMODE0 |= (2<<8 | 2<<10);
// NOT open drain
LPC_PINCON->PINMODE_OD0 &= ~(1<<4 | 1<<5);
}
return (SystemCoreClock / 20) / ((div & 0x3FF)+1);
}
示例5: CAN_device_init_1
static void CAN_device_init_1(int baud)
{
CAN_DeInit(CAN1);
/* CAN GPIOs configuration ************************************************* */
/* Enable GPIO clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
/* Connect CAN pins to Alternate Function */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_9);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_9);
initGPIO(GPIOB, GPIO_Pin_8 | GPIO_Pin_9);
/* CAN configuration ******************************************************* */
/* Enable CAN clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
initCAN(CAN1, baud);
//set default filter
CAN_device_set_filter(0, 0, 0, 0, 0);
/* Enable FIFO 0 message pending Interrupt */
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
initCANInterrupts(CAN1, USB_LP_CAN1_RX0_IRQn);
}
示例6: PIOS_CAN_Init
/**
* Initialize the CAN driver and return an opaque id
* @param[out] id the CAN interface handle
* @param[in] cfg the configuration structure
* @return 0 if successful, negative otherwise
*/
int32_t PIOS_CAN_Init(uintptr_t *can_id, const struct pios_can_cfg *cfg)
{
PIOS_DEBUG_Assert(can_id);
PIOS_DEBUG_Assert(cfg);
can_dev = (struct pios_can_dev *) PIOS_CAN_alloc();
if (!can_dev) goto out_fail;
/* Bind the configuration to the device instance */
can_dev->cfg = cfg;
/* Configure the CAN device */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* Map pins to CAN function */
if (can_dev->cfg->remap) {
if (can_dev->cfg->rx.gpio != 0)
GPIO_PinAFConfig(can_dev->cfg->rx.gpio,
can_dev->cfg->rx.pin_source,
can_dev->cfg->remap);
if (can_dev->cfg->tx.gpio != 0)
GPIO_PinAFConfig(can_dev->cfg->tx.gpio,
can_dev->cfg->tx.pin_source,
can_dev->cfg->remap);
}
/* Initialize the CAN Rx and Tx pins */
if (can_dev->cfg->rx.gpio != 0)
GPIO_Init(can_dev->cfg->rx.gpio, (GPIO_InitTypeDef *)&can_dev->cfg->rx.init);
if (can_dev->cfg->tx.gpio != 0)
GPIO_Init(can_dev->cfg->tx.gpio, (GPIO_InitTypeDef *)&can_dev->cfg->tx.init);
*can_id = (uintptr_t)can_dev;
CAN_DeInit(can_dev->cfg->regs);
CAN_Init(can_dev->cfg->regs, (CAN_InitTypeDef *)&can_dev->cfg->init);
/* CAN filter init */
CAN_FilterInitTypeDef CAN_FilterInitStructure;
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 = 1;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
// Enable the receiver IRQ
NVIC_Init((NVIC_InitTypeDef*) &can_dev->cfg->rx_irq.init);
NVIC_Init((NVIC_InitTypeDef*) &can_dev->cfg->tx_irq.init);
return(0);
out_fail:
return(-1);
}
示例7: TSVN_CAN_Init
void TSVN_CAN_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap2_CAN1 , ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_PD01 , ENABLE);
CAN_DeInit(CAN1);
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_InitStructure.CAN_BS1 = CAN_BS1_3tq; //3
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq; //5
CAN_InitStructure.CAN_Prescaler = 4;
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);
CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE);
CAN_Init(CAN1, &CAN_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
示例8: InitCAN
void InitCAN(void)
{
// Setup CAN Pins
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN | CAN_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Alternate functions
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
// Setup CAN-modules
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* CAN register init */
CAN_DeInit(CAN1);
/* CAN cell init */
CAN_InitTypeDef CAN_InitStructure;
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_3tq;
/* CAN Baudrate = 500 KBps (CAN clocked at 42 MHz) */
CAN_InitStructure.CAN_BS1 = CAN_BS1_4tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler = (42000000 / 7) / 500000;
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitTypeDef CAN_FilterInitStructure;
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);
/* Enable FIFO 0 message pending Interrupt */
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
}
示例9: CAN_Configuration
void CAN_Configuration(void)
{
/* CAN1 Periph clock enable */
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN register init */
CAN_DeInit(CAN1);
CAN_DeInit(CAN2);
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_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 16;//2 4=1m 8=500k
CAN_Init(CAN1, &CAN_InitStructure);
CAN_Init(CAN2, &CAN_InitStructure);
/* CAN filter init */
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_FilterInitStructure.CAN_FilterNumber=0;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber=14;
CAN_FilterInit(&CAN_FilterInitStructure);
}
示例10: CAN_Configuration
/**
* @file CAN_Configuration
* @brief Configures the CAN
* @param 無
* @retval 無
*/
void CAN_Configuration(void)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
GPIO_Configuration();
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE; /* 時間觸發禁止, 時間觸發:CAN硬件的內部定時器被激活,並且被用於產生時間戳 */
CAN_InitStructure.CAN_ABOM = DISABLE; /* 自動離線禁止,自動離線:一旦硬件監控到128次11個隱性位,就自動退出離線狀態。在這裏要軟件設定後才能退出 */
CAN_InitStructure.CAN_AWUM = DISABLE; /* 自動喚醒禁止,有報文來的時候自動退出休眠 */
CAN_InitStructure.CAN_NART = DISABLE; /* 報文重傳, 如果錯誤一直傳到成功止,否則隻傳一次 */
CAN_InitStructure.CAN_RFLM = DISABLE; /* 接收FIFO鎖定, 1--鎖定後接收到新的報文摘不要,0--接收到新的報文則覆蓋前一報文 */
CAN_InitStructure.CAN_TXFP = ENABLE; /* 發送優先級 0---由標識符決定 1---由發送請求順序決定 */
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal; /* 模式 */
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; /* 重新同步跳寬,隻有can硬件處於初始化模式時才能訪問這個寄存器 */
CAN_InitStructure.CAN_BS1 = CAN_BS1_4tq; /* 時間段1 */
CAN_InitStructure.CAN_BS2 = CAN_BS2_3tq; /* 時間段2 */
CAN_InitStructure.CAN_Prescaler = 45; /* 波特率預分頻數 */
/* 波特率計算方法 */
/* CANbps= Fpclk/((BRP+1)*((Tseg1+1)+(Tseg2+1)+1) 此處計算為 CANbps=36000000/(45*(4+3+1))=100kHz */ //此處Tseg1+1 = CAN_BS1_8tp
/* 配置大方向: Tseg1>=Tseg2 Tseg2>=tq; Tseg2>=2TSJW */
if (CAN_Init(CAN1,&CAN_InitStructure) == CANINITFAILED)
{
/* 初始化時先設置CAN_MCR的初始化位 */
/* 然後查看硬件是否真的設置了CAN_MSR的初始化位來確認是否進入了初始化模式 */
}
/* 配置CAN過濾器 */
/* 32位對應的id */
/* stdid[10:0],extid[17:0],ide,rtr */
/* 16位對應的id */
/* stdid[10:0],ide,rtr,extid[17:15] */
/* 一般使用屏蔽模式 */
/* 要注意的是fifo接收存滿了中斷,還有就是fifo的概念,即取的一直是最早那一個數據, 要釋放才能取下一個數據 */
/* 常使用的中斷有 */
/* 1,有信息中斷,即fifo掛號中斷 */
/* 2,fifo滿中斷 */
/* 3,fifo滿之後又有信息來則中斷,即fifo溢出中斷 */
CAN_FilterInitStructure.CAN_FilterNumber=0; /* 過濾器0 */
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; /* 屏敝模式 */
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; /* 32位 */
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; /* 以下四個都為0, 表明不過濾任何id */
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=0; /* 能夠通過該過濾器的報文存到fifo0中 */
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;
CAN_ITConfig(CAN1,CAN_IT_FMP0, ENABLE); /* 掛號中斷, 進入中斷後讀fifo的報文函數釋放報文清中斷標誌 */
CAN_FilterInit(&CAN_FilterInitStructure);
}
示例11: CAN_Open
void CAN_Open()
{
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
// Configure CAN pin: RX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure CAN pin: TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* CAN register init */
CAN_DeInit();
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_NART=ENABLE; //no automatic retransmission
CAN_InitStructure.CAN_RFLM=DISABLE;
CAN_InitStructure.CAN_TXFP=DISABLE;
CAN_InitStructure.CAN_Mode=CAN_Mode_Normal;
//CAN block is clocked with Low Speed APB1 clock (PCLK1) = 36MHz
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1=CAN_BS1_9tq; //CAN_BS1_8tq @ 24mhz
CAN_InitStructure.CAN_BS2=CAN_BS2_8tq; //CAN_BS2_7tq @24mhz
CAN_InitStructure.CAN_Prescaler=4; //=3 [email protected]
CAN_Init(&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);
}
示例12: RCC_APB1PeriphClockCmd
/**
* \brief Call this method to make the CANTestcase driver configure pins,
* set up the CAN peripheral et cetera.
*/
void CANTestcase::setUp()
{
// Enable CAN1 peripheral clock.
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,ENABLE);
// Enable GPIO clock of CAN_Tx and CAN_Rx pins.
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
/* Configure CAN pin: RX */
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure CAN pin: TX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure CAN peripheral:
CAN_InitTypeDef CAN_InitStructure;
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = ENABLE;
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_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 20;
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitTypeDef CAN_FilterInitStructure;
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);
}//eof
示例13: CAN2_Configuration
void CAN2_Configuration(void)
{
CAN_InitTypeDef can;
CAN_FilterInitTypeDef can_filter;
GPIO_InitTypeDef gpio;
NVIC_InitTypeDef nvic;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_CAN2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_CAN2);
gpio.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 ;
gpio.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOB, &gpio);
nvic.NVIC_IRQChannel = CAN2_RX0_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 1;
nvic.NVIC_IRQChannelSubPriority = 0;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
CAN_DeInit(CAN2);
CAN_StructInit(&can);
can.CAN_TTCM = DISABLE;
can.CAN_ABOM = DISABLE;
can.CAN_AWUM = DISABLE;
can.CAN_NART = DISABLE;
can.CAN_RFLM = DISABLE;
can.CAN_TXFP = ENABLE;
can.CAN_Mode = CAN_Mode_Normal;
can.CAN_SJW = CAN_SJW_1tq;
can.CAN_BS1 = CAN_BS1_9tq;
can.CAN_BS2 = CAN_BS2_4tq;
can.CAN_Prescaler = 3; //CAN BaudRate 42/(1+9+4)/3=1Mbps
CAN_Init(CAN2, &can);
can_filter.CAN_FilterNumber=14;
can_filter.CAN_FilterMode=CAN_FilterMode_IdMask;
can_filter.CAN_FilterScale=CAN_FilterScale_32bit;
can_filter.CAN_FilterIdHigh=0x0000;
can_filter.CAN_FilterIdLow=0x0000;
can_filter.CAN_FilterMaskIdHigh=0x0000;
can_filter.CAN_FilterMaskIdLow=0x0000;
can_filter.CAN_FilterFIFOAssignment=0;//the message which pass the filter save in fifo0
can_filter.CAN_FilterActivation=ENABLE;
CAN_FilterInit(&can_filter);
CAN_ITConfig(CAN2,CAN_IT_FMP0,ENABLE);
}
示例14: CANController_Init
void CANController_Init(void) {
CAN_FilterInitTypeDef CAN_FilterInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
// Configure CAN pin: RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure CAN pin: TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Reset CAN1
CAN_DeInit(CAN1);
// CAN filter init - all messages to FIFO0
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);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 14;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = CAN1_SCE_IRQn;
NVIC_Init(&NVIC_InitStructure);
// enable intertrupts, TODO: less magic values !
CAN1->IER = 0x00008F13; // enable all interrupts (except FIFOx full/overrun, sleep/wakeup)
}
示例15: EOBD_CAN_Configure
void EOBD_CAN_Configure(int baudrate)
{
CAN_InitTypeDef CAN_InitStructure;
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_7tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_6tq;
CAN_InitStructure.CAN_Prescaler = scale250KB; // 1/((1/112M)*(bs1+bs2+1))*scale
CAN_Init(CAN1,&CAN_InitStructure);
}