Part Number:LAUNCHXL-F280025C
InitPeripheralClocks 打开了时钟。
CpuSysRegs.PCLKCR19.bit.LIN_A = 1;
CpuSysRegs.PCLKCR19.bit.LIN_B = 1; //低速用了10分频,100MHZ/10=10M
端口复用 // 复用值1011b GPIO22=LINB_TX复用11,GPIO23=LINB_RX复用11,
GpioCtrlRegs.GPAGMUX2.bit.GPIO22 = 0x2;
GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 0x3;
GpioCtrlRegs.GPAGMUX2.bit.GPIO23 = 0x02;
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 0x01; //=RX
寄存器初始化(LIN作用UART使用)
EALLOW;
LinbRegs.SCIGCR0.bit.RESET = 0; // Into reset
LinbRegs.SCIGCR0.bit.RESET = 1; // Out of reset
DELAY_US(1000);
LinbRegs.SCIGCR1.bit.SWnRST = 0; // Into software reset
DELAY_US(1000);
//SCI Configurations
LinbRegs.SCIGCR1.bit.COMMMODE = 0; // Idle-Line Mode
LinbRegs.SCIGCR1.bit.TIMINGMODE = 1; // Asynchronous Timing
LinbRegs.SCIGCR1.bit.PARITYENA = 0; // No Parity Check
LinbRegs.SCIGCR1.bit.PARITY = 0; // Odd Parity
LinbRegs.SCIGCR1.bit.STOP = 0; // One Stop Bit
LinbRegs.SCIGCR1.bit.CLK_MASTER = 1; // Enable SCI Clock
LinbRegs.SCIGCR1.bit.LINMODE = 0; // SCI Mode
LinbRegs.SCIGCR1.bit.SLEEP = 0; // Ensure Out of Sleep
LinbRegs.SCIGCR1.bit.ADAPT = 0; //auto baudrate
LinbRegs.SCIGCR1.bit.MBUFMODE = 0; // none Buffer Mode
LinbRegs.SCIGCR1.bit.LOOPBACK = 1; // External Loopback 使用1或0都是同样的错误。
LinbRegs.SCIGCR1.bit.CONT = 1; // Continue on Suspend in Emulation Mode
LinbRegs.SCIGCR1.bit.RXENA = 1; // Enable RX
LinbRegs.SCIGCR1.bit.TXENA = 1; // Enable TX
LinbRegs.SCIGCR2.bit.POWERDOWN = 0;
//Ensure IODFT is disabled
LinbRegs.IODFTCTRL.bit.IODFTENA = 0x0;
//Set transmission length )
LinbRegs.SCIFORMAT.bit.*** = 7; // Eight bits
LinbRegs.SCIFORMAT.bit.LENGTH = 0; // 1 byte
//Set baudrate
LinbRegs.BRSR.bit.SCI_LIN_PSL = 1041; //LSPCLKDIV=10, 10M/9600
LinbRegs.BRSR.bit.SCI_LIN_PSH = ;
LinbRegs.BRSR.bit.M = 0;
// Enable interrupts
LinbRegs.SCISETINT.bit.SETRXINT = 1; // Enable RX interrupt
LinbRegs.SCISETINT.bit.SETTXINT = 1; // Enable TX interrupt,要发送的时候再打开。
//Set interrupt priority
LinbRegs.SCICLEARINTLVL.all = 0xFFFFFFFF; // Set Int level of all interrupts to LVL 0
DELAY_US(1000);
LinbRegs.SCIGCR1.bit.SWnRST = 1; // bring out of software reset
DELAY_US(1000);
// Disable write to protected registers
EDIS;
其它的一些中断配置代码:
EALLOW;
PieVectTable.LINB_0_INT = &Rx2Isr;
PieVectTable.LINB_1_INT = &Tx2Isr;
EDIS;
PieCtrlRegs.PIEIER8.bit.INTx9 = 1; //LINA0
PieCtrlRegs.PIEIER8.bit.INTx10 = 1; //LINA1
PieCtrlRegs.PIEIER8.bit.INTx11 = 1; //LINB0
PieCtrlRegs.PIEIER8.bit.INTx12 = 1; //LINB1
IER |= M_INT8;//LIN
通信收发没任何反应,检查状态寄存器发现LinbRegs.SCIFLR寄存器的BRKDT和BUSY一直是1,每个DELAY_US(1000)后观察都一样,不知道这个错误是如何产生的?(开发板的杜邦线已经插开)
Ben Qin:
你好,我查找下相关资料,稍后回复您。
,
jiangtao zhou:
有可能是漏配置,但不知道是漏了哪里。例子里面有那种函数型的,但是看不清楚函数对寄存器做了什么,非常难看
,
Ben Qin:
这里是多少?
你开启了全局中断吗?
,
jiangtao zhou:
我看了CCS里的代码,PSH这里是0,粘贴上来填写注释时不小心弄掉0了。
全局中断肯定开启了,SCI,ADC,PWM其它都是可以工作的,因为SCI一个太少了,要扩展LIN成SCI
EALLOW; //SEARCH "PIE Channel Mapping" PieVectTable.EPWM1_INT = &Epwm1Isr; PieVectTable.EPWM2_INT = &Epwm2Isr; PieVectTable.EPWM3_INT = &Epwm3Isr; //PieVectTable.EPWM4_INT = &Epwm4Isr; //PieVectTable.EPWM5_INT = &Epwm5Isr; //PieVectTable.EPWM6_INT = &Epwm6Isr; PieVectTable.ADCA1_INT = &Epwm1AdcIsr;
PieVectTable.SCIA_RX_INT = &Rx0Isr; //9.1=RX PieVectTable.SCIA_TX_INT = &Tx0Isr; //9.2=TX
PieVectTable.LINA_0_INT = &Rx1Isr; //8.9~8.12 PieVectTable.LINA_1_INT = &Rx1Isr;
PieVectTable.LINB_0_INT = &Rx2Isr; PieVectTable.LINB_1_INT = &Tx2Isr;
EDIS;
PieCtrlRegs.PIECTRL.bit.ENPIE=1; //SEARCH "PIE Channel Mapping" PieCtrlRegs.PIEIER1.bit.INTx1 = 1;//1.1为ADCA1中断(ADC TOTAL:ADCA1~A4,B1~B4,C1~C4,D1~D4)
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;//3.1~3.7为PWM中断1~PWM7 PieCtrlRegs.PIEIER3.bit.INTx2 = 1;//3.1~3.7为PWM中断1~PWM7 PieCtrlRegs.PIEIER3.bit.INTx3 = 1;//3.1~3.7为PWM中断1~PWM7 //PieCtrlRegs.PIEIER3.bit.INTx4 = 1;//3.1~3.7为PWM中断1~PWM7 //PieCtrlRegs.PIEIER3.bit.INTx5 = 1;//3.1~3.7为PWM中断1~PWM7 //PieCtrlRegs.PIEIER3.bit.INTx6 = 1;//3.1~3.7为PWM中断1~PWM7
PieCtrlRegs.PIEIER8.bit.INTx9 = 1; //LINA0 PieCtrlRegs.PIEIER8.bit.INTx10 = 1; //LINA1 PieCtrlRegs.PIEIER8.bit.INTx11 = 1; //LINB0 PieCtrlRegs.PIEIER8.bit.INTx12 = 1; //LINB1
PieCtrlRegs.PIEIER9.bit.INTx1 = 1; //9.1=SCIA_RX中断 PieCtrlRegs.PIEIER9.bit.INTx2 = 1; //9.2=SCIA_TX中断
IER |= M_INT1;//1大类,1小类是ADC_A1,还有A2,A3,A4, B1~B4,…,D1~D4 IER |= M_INT3;//3大类,1~7小类是EPWM1_INT~7 IER |= M_INT8;//LIN IER |= M_INT9;//9大类是串口
EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM
,
Ben Qin:
jiangtao zhou 说:检查状态寄存器发现LinbRegs.SCIFLR寄存器的BRKDT和BUSY一直是1
可以用单步调试检查下什么时候置1的吗?
,
jiangtao zhou:
经过单步 ,发现是在 InitPeripheralClocks的CpuSysRegs.PCLKCR19.bit.LIN_B = 1; 这一行发生的错误置位。
下面的代码,使用外置晶振,和内置RC结果都一样。再后来经过RESET和SWRST后这两个标志也没有清0
#if defined(USE_PLL_SRC_XTAL) InitSysPll(XTAL_OSC, IMULT_10, REFDIV_1, ODIV_3, PLLCLK_BY_1, SYSCTL_DCC_BASE0);#elif defined(USE_PLL_SRC_INTOSC) InitSysPll(INT_OSC2, IMULT_30, REFDIV_1, ODIV_3, PLLCLK_BY_1, SYSCTL_DCC_BASE0);#endif
,
Ben Qin:
试过TI的例程吗?
jiangtao zhou 说:发现是在 InitPeripheralClocks的CpuSysRegs.PCLKCR19.bit.LIN_B = 1; 这一行发生的错误置位
是硬件的问题吗? 如果是硬件问题,TI的例程应该也用不了。
,
jiangtao zhou:
我换了一块280049的LANUCH开发板后,LinbRegs.SCIFLR全变成0了(执行寄存器初始化后还是全0),我看用户手册说要TXRDY为1时,才可以发送
if (LinbRegs.SCIFLR.bit.TXRDY == 1) LinbRegs.SCITD.bit.TD = 0xAA; 这个一直没机会等到进入
,
Ben Qin:
jiangtao zhou 说:我换了一块280049的LANUCH开发板后
烧录的是TI的例程吗?哪个例程?