上传者: u013789497
|
上传时间: 2021-10-22 09:02:14
|
文件大小: 17.37MB
|
文件类型: -
stm32L073xx CAN通信实验 HAL库函数版本
void Delay(__IO uint32_t nCount);
/*
* º¯ÊýÃû£ºmain
* ÃèÊö £ºÖ÷º¯Êý
* ÊäÈë £ºÎÞ
* Êä³ö £ºÎÞ
*/
int main(void)
{
LED_GPIO_Config();
LED_BLUE;
/* ÅäÖô®¿ÚΪ£º115200 8-N-1 */
USART_Config();
printf("\r\n ÕâÊÇÒ»¸öCANͨѶʵÑé \r\n");
CAN_Config() ;
Key_GPIO_Config();
printf("\r\n °´KEY1°´¼ü·¢ËÍÊý¾Ý\r\n");
while(1)
{
if( Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN) == KEY_ON )
{
uint8_t box;
CAN_Tran_Data.StdId = 0;
CAN_Tran_Data.ExtId = PASS_ID;
CAN_Tran_Data.RTR = CAN_RTR_Data;
CAN_Tran_Data.IDE = CAN_Id_Extended ;
CAN_Tran_Data.DLC = 1;
CAN_Tran_Data.Data[0] = 10;
box = CAN_Transmit(CAN1,&CAN;_Tran_Data);
while(CAN_TransmitStatus(CAN1,box) == CAN_TxStatus_Failed);
printf("\r\n Êý¾Ý°ü·¢ËÍÍê³É\r\n");
}
if(flag == 1)
{
printf("\r\n½ÓÊÕµ½µÄÊý¾Ý£º%d\r\n",CAN_Rece_Data.Data[0]);
flag = 0;
}
else
{
}
}
}