Other Parts Discussed in Thread: CONTROLSUITE
controlSUITE的CAN例程中(C:\ti\controlSUITE\device_support\F2837xD\v210\F2837xD_examples_Cpu1\can_external_transmit\cpu01),改了CANB为发送口,CAN调试器需要设置成250K才能通信成功。
发现sysctl.c代码中有void SysCtlClockSet(uint32_t ui32Config)函数,其中包含设置SYSCTL_OSCSRC_OSC1和2,以及SYSCTL_OSCSRC_XTAL的频率参数,例程源代码如下:
#define SYSCTL_OSCSRC_OSC2 0x00000000
#define SYSCTL_OSCSRC_XTAL 0x00010000
#define SYSCTL_OSCSRC_OSC1 0x00020000
/*...省略....*/
void
SysCtlClockSet(uint32_t ui32Config)
{
/*...省略....*/
if(clock_source != ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL)
{
//Configure Oscillator
EALLOW;
switch (clock_source)
{
case ((uint32_t)SYSCTL_OSCSRC_OSC2 >> SYSCTL_OSCSRC_S):
ClkCfgRegs.CLKSRCCTL1.bit.INTOSC2OFF=0; // Turn on INTOSC2
ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 0; // Clk Src = INTOSC2
break;
case ((uint32_t)SYSCTL_OSCSRC_XTAL >> SYSCTL_OSCSRC_S):
ClkCfgRegs.CLKSRCCTL1.bit.XTALOFF=0; // Turn on XTALOSC
ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 1; // Clk Src = XTAL
break;
case ((uint32_t)SYSCTL_OSCSRC_OSC1 >> SYSCTL_OSCSRC_S):
ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 2; // Clk Src = INTOSC1
break;
}
EDIS;
}
/*...省略....*/
}
控制板上采用的10Mhz晶振,从结果反推程序可能采用的是SYSCTL_OSCSRC_OSC1的参数,即20Mhz晶振。但是通过searchtext方式没有找到SysCtlClockSet函数的调用,这又陷入了死胡同。
请问系统时钟如何确定以及修改正确?
在下附上本人的程序,CAN用的12和17gpio
//.TI.ramfunc // // Included Files // #include "F28x_Project.h" //#include "F2837xD_Ipc_drivers.h" #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_can.h" #include "driverlib/can.h" // // Globals // Uint16 on1 = 0; Uint16 on2 = 0; unsigned char txMsgData[4]; unsigned char rxMsgData[4]; tCANMsgObject sTXCANMessage; tCANMsgObject sRXCANMessage; // // Function Prototypes // // // Main // void main(void) { InitSysCtrl();//20MXTAL_OSC DEVICE_SYSCLK_FREQ // EALLOW; // ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 1; // Clk Src = XTAL // EDIS; InitGpio(); GPIO_SetupPinMux(31, GPIO_MUX_CPU1, 0); GPIO_SetupPinOptions(31, GPIO_OUTPUT, GPIO_PUSHPULL); GPIO_SetupPinMux(17, GPIO_MUX_CPU1, 2); // GPIO17 - CANRXA GPIO_SetupPinMux(12, GPIO_MUX_CPU1, 2); // GPIO12 - CANTXA GPIO_SetupPinOptions(17, GPIO_INPUT, GPIO_ASYNC); GPIO_SetupPinOptions(12, GPIO_OUTPUT, GPIO_PUSHPULL); CANInit(CANB_BASE); CANClkSourceSelect(CANB_BASE, 0); CANBitRateSet(CANB_BASE, 200000000, 500000); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM CANEnable(CANB_BASE); sTXCANMessage.ui32MsgID = 0x0001; sTXCANMessage.ui32MsgIDMask = 0; sTXCANMessage.ui32Flags = 0; sTXCANMessage.ui32MsgLen = 4; sTXCANMessage.pucMsgData = txMsgData; txMsgData[0] = 0x12; txMsgData[1] = 0x34; txMsgData[2] = 0x56; txMsgData[3] = 0x78; for(;;) { on1 = ~on1; GPIO_WritePin(31, on1); CANMessageSet(CANB_BASE, 1, &sTXCANMessage, MSG_OBJ_TYPE_TX); DELAY_US(1000*250); } } // // End of file //
其中被屏蔽的三条语句:
// EALLOW;
// ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 1; // Clk Src = XTAL
// EDIS;
是为了尝试修改时钟频率,但是还是不行