-
谢谢谢谢:victory:
-
谢谢各位大哥
-
解决了!!!!!!!!!!!!!!!我的天天老爷,收发器ISO1050,CANH,CANL那端没供电!!!!!!!!!!!!!!我真是猪到家了,因为底板电源种类比较多,没有认真检查,浪费了将近一周的时间,天啊!!!!!!!!!!!!!程序是没有问题的!!!!!!!!!!
-
int main(void)
{
RCC_ClocksTypeDef RCC_Clocks;
//&**** SysTick end of count event each 10ms *****&/
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
NVIC_Config();
LED_Config();
CAN_Config();
while(1)
{
CAN_Trans();
Delay(60);
}
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=CAN1_RX0_IRQn; //中断请求 CAN1_RX0_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void CAN_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* Connect CAN pins to AF9 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
/* Configure CAN RX and TX pins */
/* PA11 RX-上拉输入,PA12 TX-复用推挽输出*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // 推挽输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
CAN_DeInit(CAN1);
CAN_InitStructure.CAN_TTCM = DISABLE; //time triggered communication mode
CAN_InitStructure.CAN_ABOM = DISABLE; //automatic bus-off management
CAN_InitStructure.CAN_AWUM = DISABLE; //automatic wake-up mode
CAN_InitStructure.CAN_NART = DISABLE; //non-automatic retransmission mode
CAN_InitStructure.CAN_RFLM = DISABLE; //Receive FIFO Locked mode
CAN_InitStructure.CAN_TXFP = DISABLE; //transmit FIFO priority
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
/*主板的时钟使用外部告诉时钟,25MHz,CAN clocked(APB1) at 30 MHz, set CAN Baudrate = 125KBps
than, how to calculate the Tq*/
/* 主板的时钟使用外部高速时钟,25MHz Baudrate = 500 Kbps ,CAN clocked (APB1) at 30MHz*/
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; //Specifies the maximum number of time quanta
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = 4; //30 000000/(1+6+8)/4= 30 000000/(1+2+3)/10=
CAN_Init(CAN1, &CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;// CAN_FilterMode_IdList
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; //FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
TxMessage.StdId = 0x04; //standard ID
TxMessage.ExtId = 0x00; //extend ID
TxMessage.RTR = CAN_RTR_DATA; //data frame
TxMessage.IDE = CAN_ID_STD; //standard ID
TxMessage.DLC = 1; //length of data
TxMessage.Data[0] = 0xDE;
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); // finish sending Interrupt CAN_IT_TME, Enable FIFO 0 message pending Interrupt
}
void CAN_Trans(void)
{
uint32_t i=0;
uint8_t TransmitMailbox=0;
/* Transmit Structure preparation */
TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
//CAN_Transmit(CAN1, &TxMessage);
i = 0;
//一定时间内不断发送,直到:1、发送成功==CANTXOK,2、i !=0xFFFF
while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK ) && (i != 0xFFFF)) // CAN_TxStatus_Failed
{
i++; //发送失败
}
i = 0;
while((CAN_MessagePending(CAN1, CAN_FIFO0)
-
huaiqiao 发表于 2017-3-16 14:59
还有,你可以先测测回环模式,然后再来正常模式。
回环测试是可以的,能正确运行,回环测试改为Normal模式,需要注意些什么东西呢?
-
这是主函数以及CAN的配置程序,见附件
-
huaiqiao 发表于 2017-3-14 17:38
楼主,您好,不好意思,刚出差回来。
针对你的程序,其实单单从结构上来说,代码整体感觉很乱,基本感 ...
首先,很感谢你的热心批评指导,我以后会注意的了。现在我大概是确认了不是外围电路的问题,我是使用的核心板加底板的形式的,我使用核心板和另一个CAN收发器模块,TJA1050,也是无法收发,程序还是一直在发送的时候一直处于Pending,而且没有办法进入接收中断,但是其他的中断是正常的,比如定时器中断,,,这么说的话,我的核心板是没有问题的吧?但是程序为什么执行不下去?是不是CAN应用在STM32F205上的应用和在STM32F103的应用不一样?因为以前没有使用过205系列的。
-
huaiqiao 发表于 2017-3-9 20:03
建议,先测试回环模式是否可以。。。。然后再使用正常模式。。。。。不知道相关配置代码是否可以贴出来,ca ...
贴出来了
-
回环模式是可以的,就是通信两个点之间的通讯不行
main函数:
int main(void)
{
//&*******************************************
//以下程序段只是测试核心板上的指示灯能否正常亮起
RCC_ClocksTypeDef RCC_Clocks;
//&**** SysTick end of count event each 10ms *****&/
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
NVIC_Config();
LED_Config();
CAN_Config();
while(1)
{
CAN_Polling();
}
}
void CAN_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* CAN GPIOs configuration **************************************************/
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* Connect CAN pins to AF11\12 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_CAN1);
/* Enable CAN clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
// Configure CAN RX and TX pins //
//PA11 RX-上拉输入,PA12 TX-复用推挽输出//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // 推挽输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void CAN_Polling(void)
{
uint32_t i=0;
uint8_t TransmitMailbox=0;
/* CAN configuration ********************************************************/
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE; //time triggered communication mode
CAN_InitStructure.CAN_ABOM = DISABLE; //automatic bus-off management
CAN_InitStructure.CAN_AWUM = DISABLE; //automatic wake-up mode
CAN_InitStructure.CAN_NART = DISABLE; //non-automatic retransmission mode
CAN_InitStructure.CAN_RFLM = DISABLE; //Receive FIFO Locked mode
CAN_InitStructure.CAN_TXFP = ENABLE; //transmit FIFO priority
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; //Specifies the maximum number of time quanta
/*主板的时钟使用外部告诉时钟,25MHz,CAN clocked(APB1) at 30 MHz, set CAN Baudrate = 125KBps
than, how to calculate the Tq*/
// CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq; //Specifies the number of time quanta in Bit Segment 1
// CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq; //Specifies the number of time quanta in Bit Segment 2
// CAN_InitStructure.CAN_Prescaler = 16; // Specifies the length of a time quantum
//
// /* 主板的时钟使用外部高速时钟,25MHz Baudrate = 500 Kbps ,CAN clocked (APB1) at 30MHz*/
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;// CAN_FilterMode_IdList
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; //FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
/* Transmit Structure preparation */
TxMessage.StdId = 0x00; //standard ID
TxMessage.ExtId = 0x1234; //extend ID
TxMessage.RTR = CAN_RTR_DATA; //data frame
TxMessage.IDE = CAN_ID_EXT; //standard ID
TxMessage.DLC = 2; //length of data
TxMessage.Data[0]= 0xDE;
TxMessage.Data[1]= 0xCA;
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); // finish sending Interrupt CAN_IT_TME, Enable FIFO 0 message pending Interrupt
//CAN_Transmit(CAN1,&TxMessage);
TransmitMailbox = CAN_Transmit(CAN1, &TxMessage);
//CAN_TransmitStatus 是transmit pending
if((CAN_TransmitStatus(CAN1, TransmitMailbox) == CAN_TxStatus_Ok))
{
GPIO_ResetBits(GPIOE, GPIO_Pin_3);
GPIO_ResetBits(GPIOE, GPIO_Pin_2);
}
i = 0;
//一定时间内不断发送,直到:1、发送成功==CANTXOK,2、i=0xFFFF
while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK ) && (i != 0xFFFF)) // CAN_TxStatus_Failed
{
i++; //发送失败
//GPIO_ResetBits(GPIOE, GPIO_Pin_2);
}
i = 0;
while((CAN_MessagePending(CAN1, CAN_FIFO0)
-
那得看你要学习什么单片机啊51的话用keil,430 用IAR或者CSS,STM32用keil或者VS都可以
-
http://pan.baidu.com/s/1c18vjPI
-
{:1_103:}
-
okhxyyo 发表于 2016-4-26 23:16
就是这个坛友写的啊,这个作者名字这么古怪呀,
我,,,,我的论坛名字叫mo_正_pie,那两个是真实名字的拼音,莫正佩
-
{:1_103:}
-
dcexpert 发表于 2016-4-26 11:34
串口读回来的数据可以放在缓冲区,就象我们平时用的数组。
我们的这块python板是不是没有加速度计啊?想做那个鼠标的实验,但是发现没有加速度的数据?
-
johnrey 发表于 2016-4-28 00:02
不知道你用多高的波特率,我的hlk在9600下工作还不错,不过只试过发数据
我的有人科技的那个串口转WiFi的波特率是115200的,收发数据都不错,几乎没有误码
-
wugx 发表于 2016-4-25 22:53
兄弟,你用的串口转wifi是那款?好用吗
济南有人科技的,挺好用,4、50块钱吧,关键是技术支持那一块人家做的好
-
{:1_103:}
-
原来我的板子的LED(4) 是坏的,,,,
-
赞赞赞