Hi guys,
I'm tryng to understand how to set correctly the CAN parameters.
First I initialize the GPIO:
GPIOPinConfigure(GPIO_PA0_CAN0RX);
GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_0);
GPIOPinConfigure(GPIO_PA1_CAN0TX);
GPIOPinTypeCAN(GPIO_PORTA_BASE, GPIO_PIN_1);
Then, I usually use this commands to set parameters for my purpose:
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_CAN0)){}
CANInit(CAN0_BASE);
CANBitRateSet(CAN0_BASE,CLOCK,CAN_BITRATE); (where CLOCK is 40M and CAN_BITRATE is 1M)
CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
IntEnable(INT_CAN0);
IntPrioritySet(INT_CAN0, MEDIUM_PRIORITY); (medium priority is 2)
CANEnable(CAN0_BASE);
Using this settings, I am able to send and recive data from other devices.
Now, I need to include another device, that has some specific settings; in detail:
-Baud rate is set to 1 Mbit/sec (that is the same the I use, so no problem)
-Each message has a 4 byte payload (this part is ok too)
- Bit Time = 10, TSEG1 = 6, TSEG2 = 1, Sampling Point = 80% ( I have some problems for this part)
I read, in the Tivaware driverlib UG, that this parameters can be setted using the "CANBitTimingSet(uint32_t ui32Base, tCANBitClkParms *psClkParms)" function,
So, I setted:
tCANBitClkParms MyCANClkparam;
MyCANClkparam.ui32SyncPropPhase1Seg=6; (as requirements)
MyCANClkparam.ui32Phase2Seg=1; (as requirements)
Now, in the driverlib UG there is written: "The total bit time, in quanta, is the sum of the two Seg parameters, as follows: bit_time_q = ui32SyncPropPhase1Seg + ui32Phase2Seg + 1"
That, in my case, is (6+1)+1+1 = 9 (but, from spec, i need bit time = 10!)
Then, it also written: "The equation to determine the actual bit rate is as follows: CAN Clock / ((ui32SyncPropPhase1Seg + ui32Phase2Seg + 1) x (ui32QuantumPrescaler))"
but, in the setting config, i use the CANBitRateSet(CAN0_BASE,CLOCK,CAN_BITRATE); anyway it means that 1M= 40'000'000/ ((6+1)+1+1) x ui32QuantumPrescaler
So i think that ui32QuantumPrescaler=4, even if the final result is not 1000000, but 1111111 ( am I right? )
The last question is, what value I need to put in the ui32SJW field ?
Thanks in advance
Federico