#include "stm32f10x.h"
#include <stdio.h>
void RCC_Conf(void);
void GPIO_Conf(void);
void CAN_Conf(void);
u8 CAN_TX(void);
//void NVIC_Configuration(void);
void Delay(vu32 nCount);
int main(void)
{
// GPIO_InitTypeDef GPIO_InitStructure;
// RCC_Conf();
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_Init(GPIOC, &GPIO_InitStructure);
//
// GPIO_SetBits(GPIOC, GPIO_Pin_0);
// Delay(10000);
// Delay(10000);
// Delay(10000);
// Delay(10000);
// Delay(10000);
// Delay(10000);
// GPIO_ResetBits(GPIOC, GPIO_Pin_0);
RCC_Conf();
GPIO_Conf();
CAN_Conf();
while(1)
{
CAN_TX();
Delay(100000);
}
}
void GPIO_Conf(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
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, &GPIO_InitStructure);
}
void CAN_Conf(void)
{
CAN_InitTypeDef CAN_InitStructure;
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 = 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_5tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_2tq;
CAN_InitStructure.CAN_Prescaler = 9;
CAN_Init(CAN1,&CAN_InitStructure);
}
u8 CAN_TX(void)
{
CanTxMsg TxMessage;
TxMessage.StdId = 0x7FF;
TxMessage.ExtId = 0xFF;
TxMessage.IDE = CAN_ID_EXT;
TxMessage.RTR = CAN_RTR_DATA;
TxMessage.DLC = 1;
TxMessage.Data[0] = 0x56;
//TxMessage.Data[1] = 0x00;
//TxMessage.Data[2] = 0x00;
//TxMessage.Data[3] = 0x00;
//TxMessage.Data[4] = 0x00;
//TxMessage.Data[5] = 0x00;
//TxMessage.Data[6] = 0x00;
//TxMessage.Data[7] = 0x00;
CAN_Transmit(CAN1,&TxMessage);
return(1);
}
void RCC_Conf(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,ENABLE);
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
有什么问题呢,没有使用中断,就是简单的发送程序。
编译和下载i都没问题,就是CAN调试仪的PC端接收不到数据。
|