哪位高手帮我分析一下这个程序不能同时收发can报文的问题啊,程序如下
/*
* File: ert_main.c
*
* Code generated for Simulink model 'p60010'.
*
* Model version : 1.107
* Simulink Coder version : 8.2 (R2012a) 29-Dec-2011
* TLC version : 8.2 (Dec 29 2011)
* C/C++ source code generated on : Wed Jan 13 12:01:14 2016
*
* Target selec
tion: ert.tlc
* Embedded hardware selection: Freescale->S12x
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "p60010.h" /* Model's header file */
#include "rtwtypes.h" /* MathWorks types */
#include <hidef.h>
#include "derivative.h"
#include "CAN.h"
#include "p60010_types.h"
#include "p60010_private.h"
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define BUS_CLOCK 32000000 //总线频率
#define OSC_CLOCK 16000000 //晶振频率
#define ID1 0x702 //发送标识符
#define data_len_TX 8 //发送数据长度
long i=0;
long j=0;
unsigned char k;
struct can_msg msg_send, msg_get;
void INIT_PLL(void)
{
CLKSEL &= 0x7f; //set OSCCLK as sysclk
PLLCTL &= 0x8F; //Disable PLL circuit
CRGINT &= 0xDF;
#if(BUS_CLOCK == 40000000)
SYNR = 0x44;
#elif(BUS_CLOCK == 32000000)
SYNR = 0x43;
#elif(BUS_CLOCK == 24000000)
SYNR = 0x42;
#endif
REFDV = 0x81; //PLLCLK=2×OSCCLK×(SYNR+1)/(REFDV+1)=64MHz ,fbus=32M
PLLCTL =PLLCTL|0x70; //Enable PLL circuit
asm NOP;
asm NOP;
while(!(CRGFLG&0x08)); //PLLCLK is Locked already
CLKSEL |= 0x80; //set PLLCLK as sysclk
}
void delay()
{for(i=0;i<1000;i++)
for(j=0;j<640;j++);}
void rt_OneStep(void);
void rt_OneStep(void)
{
static boolean_T OverrunFlag = 0;
/* Disable interrupts here */
/* Check for overrun */
if (OverrunFlag) {
rtmSetErrorStatus(p60010_M, "Overrun");
return;
}
OverrunFlag = TRUE;
/* Set model inputs here */
/* Step the model */
p60010_step();
/* Get model outputs here */
DDRA=0xff;
relay=PORTA_PA0;
/* Indicate task complete */
OverrunFlag = FALSE;
}
void main(void)
{
/* Initialize model */
p60010_initialize();
DDRA=0xff;
INIT_PLL();
INIT_CAN0();
while (1) {
/* Perform other application tasks here */
rt_OneStep();
for(k=0;k<8;k++)
{
msg_send.id = 0x702; //message1
msg_send.data[0] = p702_byte0;
msg_send.data[1] = 0;
msg_send.data[2] = 0;
msg_send.data[3] = 0;
msg_send.data[4] = 0;
msg_send.data[5] = 0;
msg_send.data[6] = 0;
msg_send.data[7] = 0;}
msg_send.len = data_len_TX;
msg_send.RTR = FALSE;
msg_send.prty = 0;
if(!MSCAN0SendMsg(msg_send)) //发送过程出现错误
for(;;);
{msg_send.id = 0x704; //message2
msg_send.data[0] = p704_byte0;
msg_send.data[1] = p704_byte1;
msg_send.data[2] = p704_byte2;
msg_send.data[3] = 0;
msg_send.data[4] = 0;
msg_send.data[5] = 0;
msg_send.data[6] = 0;
msg_send.data[7] = 0;}
msg_send.len = data_len_TX;
msg_send.RTR = FALSE;
msg_send.prty = 0;
if(!MSCAN0SendMsg(msg_send)) //发送过程出现错误
for(;;);
{msg_send.id = 0x666; //message3
msg_send.data[0] = p666_byte0;
msg_send.data[1] = p666_byte1;
msg_send.data[2] = 0;
msg_send.data[3] = 0;
msg_send.data[4] = 0;
msg_send.data[5] = 0;
msg_send.data[6] = 0;
msg_send.data[7] = 0;}
msg_send.len = data_len_TX;
msg_send.RTR = FALSE;
msg_send.prty = 0;
if(!MSCAN0SendMsg(msg_send)) //发送过程出现错误
for(;;);
if(MSCAN0GetMsg(&msg_get)) //接收报文
{ if(msg_get.id==0x705&&(!msg_get.RTR))
CAN0RXDSR1=p705_byte0;}
if(msg_get.id==0x701&&(!msg_get.RTR))
{CAN0RXDSR4=p701_byte4;CAN0RXDSR5=p701_byte5;}
else {for(;;);
}
/* Disable rt_OneStep() here */
/* Terminate model */
p60010_terminate();
}
}
飞思卡尔 S9S12 和 MC9S12 系列 需要资料,样品或是烧录问题的,联系Q2716106851
一周热门 更多>