void main(void) { #ifdef DEBUG debug(); #endif
RCCU_Div2Config ( ENABLE); RCCU_FCLKConfig ( RCCU_RCLK_2 ); RCCU_PCLKConfig (RCCU_RCLK_2); RCCU_MCLKConfig (RCCU_DEFAULT); RCCU_PLL1Config (RCCU_PLL1_Mul_24, RCCU_Div_2); while(RCCU_FlagStatus(RCCU_PLL1_LOCK)==RESET); RCCU_RCLKSourceConfig (RCCU_PLL1_Output) ;
APB_ClockConfig(APB1,ENABLE,CAN_Periph); // initialize the I/O ports for the CAN pins // setup GPIO 1.11 (CAN RX pin) as input Tristate CMOS GPIO_Config(GPIO1, 0x0800, GPIO_IN_TRI_CMOS);
// setup GPIO 1.12 (CAN TX pin) as output alternate Push-pull GPIO_Config(GPIO1, 0x1000, GPIO_AF_PP);
// initialize the CAN at a standard bitrate CAN_Init(CAN_CR_INIT, CAN_BITRATE_100K);
// configure the message objects CAN_InvalidateAllMsgObj(); CAN_SetUnusedMsgObj(CAN_TX_MSGOBJ); CAN_SetUnusedMsgObj(CAN_RX_MSGOBJ); CAN_SetTxMsgObj(CAN_TX_MSGOBJ, CAN_STD_ID); CAN_SetRxMsgObj(CAN_RX_MSGOBJ, CAN_STD_ID, 0, CAN_LAST_STD_ID, TRUE);
while(1) {
// transmit CAN_SendMessage(CAN_TX_MSGOBJ, &TxCanMsg); // wait until end of transmission CAN_WaitEndOfTx(); // transmission succeeded // release the message objects CAN_ReleaseTxMessage(CAN_TX_MSGOBJ); // wait wait(); } }
这是一个can的发送程序,晶振采用的是8M的,请高手帮忙看看,谢谢了。 |