mcp2515_driver.c
void canBegin(void* data, uint16_t data_rate)
{

#ifdef AUTO_SPI_INITIALIZATION
	// initialize the SPI port for interacting with can.
	pal_spi_init( data, MSB_FIRST, IDLE_LOW, LEADING_EDGE);
#endif

	pal_delay_us(5);

	canRequestMode(mcp_configuration_mode);
	//setting the bit time for CAN bus
	switch(data_rate)
	{
		case 5:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_5kBPS_CNF1, MCP_8MHz_5kBPS_CNF2, MCP_8MHz_5kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_5kBPS_CNF1, MCP_16MHz_5kBPS_CNF2, MCP_16MHz_5kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;


		case 10:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_10kBPS_CNF1, MCP_8MHz_10kBPS_CNF2, MCP_8MHz_10kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_10kBPS_CNF1, MCP_16MHz_10kBPS_CNF2, MCP_16MHz_10kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;

		case 20:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_20kBPS_CNF1, MCP_8MHz_20kBPS_CNF2, MCP_8MHz_20kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_20kBPS_CNF1, MCP_16MHz_20kBPS_CNF2, MCP_16MHz_20kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;

		case 40:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_40kBPS_CNF1, MCP_8MHz_40kBPS_CNF2, MCP_8MHz_40kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_40kBPS_CNF1, MCP_16MHz_40kBPS_CNF2, MCP_16MHz_40kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;

		case 50:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_50kBPS_CNF1, MCP_8MHz_50kBPS_CNF2, MCP_8MHz_50kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_50kBPS_CNF1, MCP_16MHz_50kBPS_CNF2, MCP_16MHz_50kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_50kBPS_CNF1, MCP_20MHz_50kBPS_CNF2, MCP_20MHz_50kBPS_CNF3);
#endif
		break;

		case 80:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_80kBPS_CNF1, MCP_8MHz_80kBPS_CNF2, MCP_8MHz_80kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_80kBPS_CNF1, MCP_16MHz_80kBPS_CNF2, MCP_16MHz_80kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_80kBPS_CNF1, MCP_20MHz_80kBPS_CNF2, MCP_20MHz_80kBPS_CNF3);
#endif
		break;

		case 100:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_100kBPS_CNF1, MCP_8MHz_100kBPS_CNF2, MCP_8MHz_100kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_100kBPS_CNF1, MCP_16MHz_100kBPS_CNF2, MCP_16MHz_100kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_100kBPS_CNF1, MCP_20MHz_100kBPS_CNF2, MCP_20MHz_100kBPS_CNF3);
#endif
		break;

		case 125:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_125kBPS_CNF1, MCP_8MHz_125kBPS_CNF2, MCP_8MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_125kBPS_CNF1, MCP_16MHz_125kBPS_CNF2, MCP_16MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_125kBPS_CNF1, MCP_20MHz_125kBPS_CNF2, MCP_20MHz_125kBPS_CNF3);
#endif
		break;

		case 200:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_200kBPS_CNF1, MCP_8MHz_200kBPS_CNF2, MCP_8MHz_200kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_200kBPS_CNF1, MCP_16MHz_200kBPS_CNF2, MCP_16MHz_200kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_200kBPS_CNF1, MCP_20MHz_200kBPS_CNF2, MCP_20MHz_200kBPS_CNF3);
#endif
		break;

		case 250:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_250kBPS_CNF1, MCP_8MHz_250kBPS_CNF2, MCP_8MHz_250kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_250kBPS_CNF1, MCP_16MHz_250kBPS_CNF2, MCP_16MHz_250kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_250kBPS_CNF1, MCP_20MHz_250kBPS_CNF2, MCP_20MHz_250kBPS_CNF3);
#endif
		break;

		case 500:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_500kBPS_CNF1, MCP_8MHz_500kBPS_CNF2, MCP_8MHz_500kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_500kBPS_CNF1, MCP_16MHz_500kBPS_CNF2, MCP_16MHz_500kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_500kBPS_CNF1, MCP_20MHz_500kBPS_CNF2, MCP_20MHz_500kBPS_CNF3);
#endif
		break;

		case 1000:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_1000kBPS_CNF1, MCP_8MHz_1000kBPS_CNF2, MCP_8MHz_1000kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_1000kBPS_CNF1, MCP_16MHz_1000kBPS_CNF2, MCP_16MHz_1000kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_1000kBPS_CNF1, MCP_20MHz_1000kBPS_CNF2, MCP_20MHz_1000kBPS_CNF3);
#endif
		break;

		default:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_125kBPS_CNF1, MCP_8MHz_125kBPS_CNF2, MCP_8MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_125kBPS_CNF1, MCP_16MHz_125kBPS_CNF2, MCP_16MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_125kBPS_CNF1, MCP_20MHz_125kBPS_CNF2, MCP_20MHz_125kBPS_CNF3);
#endif
		break;
	}

	canRequestMode(mcp_normal_mode);
}
/**
 * @brief This function makes appropriate on chip initializations for the passed CAN data rate.
 *
 * @param
 * 1. data_rate : contains the CAN bus data rate in kbps.
 *
 * @return
 * 		NOTHING.
 */
@brief This function makes appropriate on chip initializations for the passed CAN data rate.
@param
1. data_rate : contains the CAN bus data rate in kbps.

@return
NOTHING.
@brief This function makes appropriate on chip initializations for the passed CAN data rate . @param 1 . data_rate : contains the CAN bus data rate in kbps . @return NOTHING .
void canBegin(void* data, uint16_t data_rate)
{
#ifdef AUTO_SPI_INITIALIZATION
	pal_spi_init( data, MSB_FIRST, IDLE_LOW, LEADING_EDGE);
#endif
	pal_delay_us(5);
	canRequestMode(mcp_configuration_mode);
	switch(data_rate)
	{
		case 5:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_5kBPS_CNF1, MCP_8MHz_5kBPS_CNF2, MCP_8MHz_5kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_5kBPS_CNF1, MCP_16MHz_5kBPS_CNF2, MCP_16MHz_5kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;
		case 10:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_10kBPS_CNF1, MCP_8MHz_10kBPS_CNF2, MCP_8MHz_10kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_10kBPS_CNF1, MCP_16MHz_10kBPS_CNF2, MCP_16MHz_10kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;
		case 20:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_20kBPS_CNF1, MCP_8MHz_20kBPS_CNF2, MCP_8MHz_20kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_20kBPS_CNF1, MCP_16MHz_20kBPS_CNF2, MCP_16MHz_20kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;
		case 40:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_40kBPS_CNF1, MCP_8MHz_40kBPS_CNF2, MCP_8MHz_40kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_40kBPS_CNF1, MCP_16MHz_40kBPS_CNF2, MCP_16MHz_40kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_40kBPS_CNF1, MCP_20MHz_40kBPS_CNF2, MCP_20MHz_40kBPS_CNF3);
#endif
		break;
		case 50:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_50kBPS_CNF1, MCP_8MHz_50kBPS_CNF2, MCP_8MHz_50kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_50kBPS_CNF1, MCP_16MHz_50kBPS_CNF2, MCP_16MHz_50kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_50kBPS_CNF1, MCP_20MHz_50kBPS_CNF2, MCP_20MHz_50kBPS_CNF3);
#endif
		break;
		case 80:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_80kBPS_CNF1, MCP_8MHz_80kBPS_CNF2, MCP_8MHz_80kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_80kBPS_CNF1, MCP_16MHz_80kBPS_CNF2, MCP_16MHz_80kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_80kBPS_CNF1, MCP_20MHz_80kBPS_CNF2, MCP_20MHz_80kBPS_CNF3);
#endif
		break;
		case 100:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_100kBPS_CNF1, MCP_8MHz_100kBPS_CNF2, MCP_8MHz_100kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_100kBPS_CNF1, MCP_16MHz_100kBPS_CNF2, MCP_16MHz_100kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_100kBPS_CNF1, MCP_20MHz_100kBPS_CNF2, MCP_20MHz_100kBPS_CNF3);
#endif
		break;
		case 125:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_125kBPS_CNF1, MCP_8MHz_125kBPS_CNF2, MCP_8MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_125kBPS_CNF1, MCP_16MHz_125kBPS_CNF2, MCP_16MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_125kBPS_CNF1, MCP_20MHz_125kBPS_CNF2, MCP_20MHz_125kBPS_CNF3);
#endif
		break;
		case 200:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_200kBPS_CNF1, MCP_8MHz_200kBPS_CNF2, MCP_8MHz_200kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_200kBPS_CNF1, MCP_16MHz_200kBPS_CNF2, MCP_16MHz_200kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_200kBPS_CNF1, MCP_20MHz_200kBPS_CNF2, MCP_20MHz_200kBPS_CNF3);
#endif
		break;
		case 250:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_250kBPS_CNF1, MCP_8MHz_250kBPS_CNF2, MCP_8MHz_250kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_250kBPS_CNF1, MCP_16MHz_250kBPS_CNF2, MCP_16MHz_250kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_250kBPS_CNF1, MCP_20MHz_250kBPS_CNF2, MCP_20MHz_250kBPS_CNF3);
#endif
		break;
		case 500:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_500kBPS_CNF1, MCP_8MHz_500kBPS_CNF2, MCP_8MHz_500kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_500kBPS_CNF1, MCP_16MHz_500kBPS_CNF2, MCP_16MHz_500kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_500kBPS_CNF1, MCP_20MHz_500kBPS_CNF2, MCP_20MHz_500kBPS_CNF3);
#endif
		break;
		case 1000:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_1000kBPS_CNF1, MCP_8MHz_1000kBPS_CNF2, MCP_8MHz_1000kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_1000kBPS_CNF1, MCP_16MHz_1000kBPS_CNF2, MCP_16MHz_1000kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_1000kBPS_CNF1, MCP_20MHz_1000kBPS_CNF2, MCP_20MHz_1000kBPS_CNF3);
#endif
		break;
		default:
#if		MCP_CHIP_FREQ==8000000
			canSetBitTiming(MCP_8MHz_125kBPS_CNF1, MCP_8MHz_125kBPS_CNF2, MCP_8MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==16000000
			canSetBitTiming(MCP_16MHz_125kBPS_CNF1, MCP_16MHz_125kBPS_CNF2, MCP_16MHz_125kBPS_CNF3);
#elif	MCP_CHIP_FREQ==20000000
			canSetBitTiming(MCP_20MHz_125kBPS_CNF1, MCP_20MHz_125kBPS_CNF2, MCP_20MHz_125kBPS_CNF3);
#endif
		break;
	}
	canRequestMode(mcp_normal_mode);
}
void canBegin ( void * data , uint16_t data_rate ) { #ifdef AUTO_SPI_INITIALIZATION pal_spi_init ( data , MSB_FIRST , IDLE_LOW , LEADING_EDGE ) ; #endif pal_delay_us ( 5 ) ; canRequestMode ( mcp_configuration_mode ) ; switch ( data_rate ) { case 5 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_5kBPS_CNF1 , MCP_8MHz_5kBPS_CNF2 , MCP_8MHz_5kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_5kBPS_CNF1 , MCP_16MHz_5kBPS_CNF2 , MCP_16MHz_5kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_40kBPS_CNF1 , MCP_20MHz_40kBPS_CNF2 , MCP_20MHz_40kBPS_CNF3 ) ; #endif break ; case 10 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_10kBPS_CNF1 , MCP_8MHz_10kBPS_CNF2 , MCP_8MHz_10kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_10kBPS_CNF1 , MCP_16MHz_10kBPS_CNF2 , MCP_16MHz_10kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_40kBPS_CNF1 , MCP_20MHz_40kBPS_CNF2 , MCP_20MHz_40kBPS_CNF3 ) ; #endif break ; case 20 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_20kBPS_CNF1 , MCP_8MHz_20kBPS_CNF2 , MCP_8MHz_20kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_20kBPS_CNF1 , MCP_16MHz_20kBPS_CNF2 , MCP_16MHz_20kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_40kBPS_CNF1 , MCP_20MHz_40kBPS_CNF2 , MCP_20MHz_40kBPS_CNF3 ) ; #endif break ; case 40 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_40kBPS_CNF1 , MCP_8MHz_40kBPS_CNF2 , MCP_8MHz_40kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_40kBPS_CNF1 , MCP_16MHz_40kBPS_CNF2 , MCP_16MHz_40kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_40kBPS_CNF1 , MCP_20MHz_40kBPS_CNF2 , MCP_20MHz_40kBPS_CNF3 ) ; #endif break ; case 50 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_50kBPS_CNF1 , MCP_8MHz_50kBPS_CNF2 , MCP_8MHz_50kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_50kBPS_CNF1 , MCP_16MHz_50kBPS_CNF2 , MCP_16MHz_50kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_50kBPS_CNF1 , MCP_20MHz_50kBPS_CNF2 , MCP_20MHz_50kBPS_CNF3 ) ; #endif break ; case 80 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_80kBPS_CNF1 , MCP_8MHz_80kBPS_CNF2 , MCP_8MHz_80kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_80kBPS_CNF1 , MCP_16MHz_80kBPS_CNF2 , MCP_16MHz_80kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_80kBPS_CNF1 , MCP_20MHz_80kBPS_CNF2 , MCP_20MHz_80kBPS_CNF3 ) ; #endif break ; case 100 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_100kBPS_CNF1 , MCP_8MHz_100kBPS_CNF2 , MCP_8MHz_100kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_100kBPS_CNF1 , MCP_16MHz_100kBPS_CNF2 , MCP_16MHz_100kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_100kBPS_CNF1 , MCP_20MHz_100kBPS_CNF2 , MCP_20MHz_100kBPS_CNF3 ) ; #endif break ; case 125 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_125kBPS_CNF1 , MCP_8MHz_125kBPS_CNF2 , MCP_8MHz_125kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_125kBPS_CNF1 , MCP_16MHz_125kBPS_CNF2 , MCP_16MHz_125kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_125kBPS_CNF1 , MCP_20MHz_125kBPS_CNF2 , MCP_20MHz_125kBPS_CNF3 ) ; #endif break ; case 200 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_200kBPS_CNF1 , MCP_8MHz_200kBPS_CNF2 , MCP_8MHz_200kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_200kBPS_CNF1 , MCP_16MHz_200kBPS_CNF2 , MCP_16MHz_200kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_200kBPS_CNF1 , MCP_20MHz_200kBPS_CNF2 , MCP_20MHz_200kBPS_CNF3 ) ; #endif break ; case 250 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_250kBPS_CNF1 , MCP_8MHz_250kBPS_CNF2 , MCP_8MHz_250kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_250kBPS_CNF1 , MCP_16MHz_250kBPS_CNF2 , MCP_16MHz_250kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_250kBPS_CNF1 , MCP_20MHz_250kBPS_CNF2 , MCP_20MHz_250kBPS_CNF3 ) ; #endif break ; case 500 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_500kBPS_CNF1 , MCP_8MHz_500kBPS_CNF2 , MCP_8MHz_500kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_500kBPS_CNF1 , MCP_16MHz_500kBPS_CNF2 , MCP_16MHz_500kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_500kBPS_CNF1 , MCP_20MHz_500kBPS_CNF2 , MCP_20MHz_500kBPS_CNF3 ) ; #endif break ; case 1000 : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_1000kBPS_CNF1 , MCP_8MHz_1000kBPS_CNF2 , MCP_8MHz_1000kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_1000kBPS_CNF1 , MCP_16MHz_1000kBPS_CNF2 , MCP_16MHz_1000kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_1000kBPS_CNF1 , MCP_20MHz_1000kBPS_CNF2 , MCP_20MHz_1000kBPS_CNF3 ) ; #endif break ; default : #if MCP_CHIP_FREQ == 8000000 canSetBitTiming ( MCP_8MHz_125kBPS_CNF1 , MCP_8MHz_125kBPS_CNF2 , MCP_8MHz_125kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 16000000 canSetBitTiming ( MCP_16MHz_125kBPS_CNF1 , MCP_16MHz_125kBPS_CNF2 , MCP_16MHz_125kBPS_CNF3 ) ; #elif MCP_CHIP_FREQ == 20000000 canSetBitTiming ( MCP_20MHz_125kBPS_CNF1 , MCP_20MHz_125kBPS_CNF2 , MCP_20MHz_125kBPS_CNF3 ) ; #endif break ; } canRequestMode ( mcp_normal_mode ) ; }
@brief This function makes appropriate on chip initializations for the passed CAN data rate.
@brief This function makes appropriate on chip initializations for the passed CAN data rate .
// initialize the SPI port for interacting with can. //setting the bit time for CAN bus