1
Dependents: yezhong_main_controller_copy yezhong_main_controller_copy_1 yezhong_main_controller_copy yezhong_main_controller_copy-
Revision 9:a35b78afe3e3, committed 2022-01-11
- Comitter:
- yezhong
- Date:
- Tue Jan 11 02:18:01 2022 +0000
- Parent:
- 8:872137b3a8a8
- Commit message:
- 1
Changed in this revision
--- a/CAN3.cpp Mon Oct 18 13:40:02 2010 +0000 +++ b/CAN3.cpp Tue Jan 11 02:18:01 2022 +0000 @@ -6,8 +6,8 @@ #include "mcp2515_defs.h" -CAN3::CAN3(SPI& _spi, PinName ncs, PinName itr) - : spi(_spi), _mcp(spi, ncs), _itr(itr) { +CAN3::CAN3(SPI& _spi, PinName ncs)//, PinName itr) + : spi(_spi), _mcp(spi, ncs) {//, _itr(itr) { printf("\n\rcan = %d",this); } @@ -53,11 +53,11 @@ } void CAN3::rise(void (*fptr)(void)) { - _itr.rise(fptr); +// _itr.rise(fptr); } void CAN3::fall(void (*fptr2)(void)) { - _itr.fall(fptr2); +// _itr.fall(fptr2); } int CAN3::frequency(int canSpeed) { @@ -81,7 +81,8 @@ if ( _mcp.setCANCTRL_Mode(MODE_NORMAL) == MCP2515_OK) { //MODE_NORMAL MODE_LOOPBACK // printf("OK\n\r"); } else { - error("failed\n\r"); + printf("failed\n\r"); + return -1; } _mcp.dumpExtendedStatus();
--- a/CAN3.h Mon Oct 18 13:40:02 2010 +0000 +++ b/CAN3.h Tue Jan 11 02:18:01 2022 +0000 @@ -14,10 +14,10 @@ class CAN3 { SPI& spi; - InterruptIn _itr; + //InterruptIn _itr; mcp2515 _mcp; public: - CAN3(SPI& _spi, PinName ncs, PinName itr); + CAN3(SPI& _spi, PinName ncs);//, PinName itr); uint8_t read(CANMessage *msg); // int read(CANMessage& msg); void write(CANMessage* test); //int write(CANMessage msg); @@ -31,9 +31,6 @@ void rise(void (*fptr)(void)); void fall(void (*fptr2)(void)); - - - // Private functions private : uint8_t checkReceive(void); @@ -41,4 +38,4 @@ }; -#endif // _MCP2515_H_ +#endif // _CAN3_H_
--- 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
--- a/mcp2515_can.h Mon Oct 18 13:40:02 2010 +0000 +++ b/mcp2515_can.h Tue Jan 11 02:18:01 2022 +0000 @@ -21,6 +21,7 @@ #define CAN_20KBPS (1) #define CAN_125KBPS (CAN_20KBPS+1) +#define CAN_500KBPS_10MHz (59) #define CAN_1MBPS_8MHZ (58) #define CAN_500KBPS_8MHZ (57) #define CAN_250KBPS_8MHZ (56)