1
Dependents: yezhong_main_controller_copy yezhong_main_controller_copy_1 yezhong_main_controller_copy yezhong_main_controller_copy-
Diff: mcp2515.cpp
- Revision:
- 9:a35b78afe3e3
- Parent:
- 6:36e854e627f6
--- a/mcp2515.cpp Mon Oct 18 13:40:02 2010 +0000 +++ b/mcp2515.cpp Tue Jan 11 02:18:01 2022 +0000 @@ -27,7 +27,7 @@ * Version : 0.1 * * All credits to the nerds above, this source has been adapted for the - * LPC1768 platform by J.Engelman. And does'nt require and of the copyrighted + * LPC1768 platform by J.Engelman. And doesn't require and of the copyrighted * SPI or AVR controller code that Martin or co have excluded copyright. * This module remains free. * @@ -89,25 +89,31 @@ switch (canSpeed) { case (CAN_500KBPS_8MHZ) : - cfg1 = 0x04; + cfg1 = 0x04; cfg2 = 0xA0; cfg3 = 0x02; case (CAN_50KBPS_8MHZ) : - cfg1 = 0x04; //0x09; + cfg1 = 0x04; //0x09; cfg2 = 0xB8; //0x90; cfg3 = 0x05; //0x02; case (CAN_125KBPS) : - cfg1 = MCP_4MHz_125kBPS_CFG1 ; + cfg1 = MCP_4MHz_125kBPS_CFG1 ; cfg2 = MCP_4MHz_125kBPS_CFG2 ; cfg3 = MCP_4MHz_125kBPS_CFG3 ; set = 1; break; case (CAN_20KBPS) : - cfg1 = MCP_4MHz_20kBPS_CFG1 ; + cfg1 = MCP_4MHz_20kBPS_CFG1 ; cfg2 = MCP_4MHz_20kBPS_CFG2 ; cfg3 = MCP_4MHz_20kBPS_CFG3 ; set = 1; break; + case (CAN_500KBPS_10MHz) : + cfg1 = 0x00; + cfg2 = 0x92; + cfg3 = 0x02; + set = 1; + break; default: set = 0; break; @@ -128,9 +134,8 @@ //struct spi_device *spi = to_spi_device(can->cdev.dev); //struct mcp251x *chip = dev_get_drvdata(&spi->dev); //struct mcp251x_platform_data *pdata = spi->dev.platform_data; - printf("\n\rcanspeed=%d",bit_rate); - int f_osc = 16000000; //4000000; //4Mhz + int f_osc = 8000000; int tqs; /* tbit/TQ */ int brp; int ps1, ps2, propseg, sjw; @@ -455,7 +460,7 @@ //setRegister(MCP_RXB1CTRL, 0); } -uint8_t mcp2515::init( int canSpeed) { +uint8_t mcp2515::init(int canSpeed) { uint8_t res; _deselect(); @@ -471,11 +476,11 @@ return res; /* function exit on error */ } res = configRate2(canSpeed); + //res = configRate(CAN_500KBPS_10MHz); if ( res == MCP2515_OK ) { initCANBuffers(); - // enable both receive-buffers to receive messages // with std. and ext. identifiers // and enable rollover