KEAZ128 CAN收发测试(二)
PIT(10ms)
中断初始化,1ms中断
void int_PIT()
{
SIM_SCGC|=SIM_SCGC_PIT_MASK; //Enable bus clock to PIT Module
PIT_MCR = 0x0; //Turn On PIT module,Freeze disable
PIT_LDVAL0 = 20000-1;
PIT_TCTRL0 |= PIT_TCTRL_TIE_MASK;//Enable interrupt
PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK;//PIT:Start timer
NVIC_ClearPendingIRQ(PIT_CH0_IRQn);
NVIC_EnableIRQ(PIT_CH0_IRQn);
NVIC_SetPriority(PIT_CH0_IRQn,1);
}
TimeCounter_10ms进行计数
void PIT_CH0_IRQHandler()
{
TimeCounter_10ms++;
PIT_TFLG0 |= PIT_TFLG_TIF_MASK; /* Clear PIT0 flag */
}
计数等于10,进行数据Load,发送CAN报文
void Task10ms()
{
//10ms processor
if (TimeCounter_10ms==10)
{
NVIC_DisableIRQ(PIT_CH0_IRQn);
TimeCounter_10ms=0;
uint8_t err_status;
uint8_t data_rec[9];
data_rec[0] = 8;
data_rec[1] = 1;
data_rec[2] = 2;
data_rec[3] = 3;
data_rec[4] = 4;
data_rec[5] = 5;
data_rec[6] = 6;
data_rec[7] = 7;
data_rec[8] = 8;
err_status = Load_CAN_MB(0, 9, data_rec);
err_status = Load_CAN_MB(0, 10, data_rec);
err_status = Load_CAN_MB(0, 11, data_rec);
err_status = Load_CAN_MB(0, 12, data_rec);
err_status = Load_CAN_MB(0, 13, data_rec);
err_status = Transmit_CAN_MB(0, 5);
err_status = Transmit_CAN_MB(0, 9);
err_status = Transmit_CAN_MB(0, 10);
err_status = Transmit_CAN_MB(0, 11);
err_status = Transmit_CAN_MB(0, 12);
err_status = Transmit_CAN_MB(0, 13);
/*******************************************************/
}
NVIC_EnableIRQ(PIT_CH0_IRQn);
}
CAN接收到的0x300报文再通过0x123发出去
while(1)
{
Get_BUF00_msg();
Get_BUF01_msg();
Task10ms();
}
void Get_BUF00_msg()
{
err_status = Check_CAN_MB_Status(0, 0, buffer00_status);
if( buffer00_status[0] == NEWDATA)
{
uint8_t cnt;
err_status = Read_CAN_MB_Data(0, 0, Buffer00);
for(cnt=1;cnt<9;cnt++)
{
Buffer00_Data[cnt-1] = Buffer00[cnt];
}
err_status = Load_CAN_MB(0, 5, Buffer00);
}
}